summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrun_tests33
1 files changed, 19 insertions, 14 deletions
diff --git a/run_tests b/run_tests
index a09ab382..30e7b55a 100755
--- a/run_tests
+++ b/run_tests
@@ -1,4 +1,4 @@
1#!/usr/bin/env python 1#!/usr/bin/env python3
2# -*- coding:utf-8 -*- 2# -*- coding:utf-8 -*-
3# Copyright 2019 The Android Open Source Project 3# Copyright 2019 The Android Open Source Project
4# 4#
@@ -20,22 +20,26 @@ from __future__ import print_function
20 20
21import errno 21import errno
22import os 22import os
23import shutil
23import subprocess 24import subprocess
24import sys 25import sys
25 26
26 27
27def run_pytest(cmd, argv): 28def find_pytest():
28 """Run the unittests via |cmd|.""" 29 """Try to locate a good version of pytest."""
29 try: 30 # Use the Python 3 version if available.
30 return subprocess.call([cmd] + argv) 31 ret = shutil.which('pytest-3')
31 except OSError as e: 32 if ret:
32 if e.errno == errno.ENOENT: 33 return ret
33 print('%s: unable to run `%s`: %s' % (__file__, cmd, e), file=sys.stderr) 34
34 print('%s: Try installing pytest: sudo apt-get install python-pytest' % 35 # Hopefully this is a Python 3 version.
35 (__file__,), file=sys.stderr) 36 ret = shutil.which('pytest')
36 return 127 37 if ret:
37 else: 38 return ret
38 raise 39
40 print(f'{__file__}: unable to find pytest.', file=sys.stderr)
41 print(f'{__file__}: Try installing: sudo apt-get install python-pytest',
42 file=sys.stderr)
39 43
40 44
41def main(argv): 45def main(argv):
@@ -48,7 +52,8 @@ def main(argv):
48 pythonpath += os.pathsep + oldpythonpath 52 pythonpath += os.pathsep + oldpythonpath
49 os.environ['PYTHONPATH'] = pythonpath 53 os.environ['PYTHONPATH'] = pythonpath
50 54
51 return run_pytest('pytest', argv) 55 pytest = find_pytest()
56 return subprocess.run([pytest] + argv, check=True)
52 57
53 58
54if __name__ == '__main__': 59if __name__ == '__main__':