diff options
Diffstat (limited to 'run_tests')
| -rwxr-xr-x | run_tests | 33 |
1 files changed, 19 insertions, 14 deletions
| @@ -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 | ||
| 21 | import errno | 21 | import errno |
| 22 | import os | 22 | import os |
| 23 | import shutil | ||
| 23 | import subprocess | 24 | import subprocess |
| 24 | import sys | 25 | import sys |
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | def run_pytest(cmd, argv): | 28 | def 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 | ||
| 41 | def main(argv): | 45 | def 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 | ||
| 54 | if __name__ == '__main__': | 59 | if __name__ == '__main__': |
