summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-12-01 13:27:56 -0500
committerMike Frysinger <vapier@google.com>2020-12-01 19:29:47 +0000
commit9dfd69f7730bc73d3a1e3a97e99041dcf28f3d1f (patch)
tree372db51e17d9ac2560907b59d38fc9ae588d4d9a
parent08eb63cea430316ce075c68f365e87c8ef0eea52 (diff)
downloadgit-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-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__':