diff options
author | Mike Frysinger <vapier@google.com> | 2020-12-01 13:27:56 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-12-01 19:29:47 +0000 |
commit | 9dfd69f7730bc73d3a1e3a97e99041dcf28f3d1f (patch) | |
tree | 372db51e17d9ac2560907b59d38fc9ae588d4d9a | |
parent | 08eb63cea430316ce075c68f365e87c8ef0eea52 (diff) | |
download | git-repo-9dfd69f7730bc73d3a1e3a97e99041dcf28f3d1f.tar.gz |
run_tests: rewrite to use Python 3
Some distros still have `pytest` as Python 2 and sep `pytest-3`.
Rewrite this script to use `pytest-3` if available.
Change-Id: I430ed8792e7b0da9b217f948f2e983aa62bf1299
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/290503
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
-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__': |