mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
08eb63cea4
commit
9dfd69f773
33
run_tests
33
run_tests
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
# Copyright 2019 The Android Open Source Project
|
# Copyright 2019 The Android Open Source Project
|
||||||
#
|
#
|
||||||
@ -20,22 +20,26 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def run_pytest(cmd, argv):
|
def find_pytest():
|
||||||
"""Run the unittests via |cmd|."""
|
"""Try to locate a good version of pytest."""
|
||||||
try:
|
# Use the Python 3 version if available.
|
||||||
return subprocess.call([cmd] + argv)
|
ret = shutil.which('pytest-3')
|
||||||
except OSError as e:
|
if ret:
|
||||||
if e.errno == errno.ENOENT:
|
return ret
|
||||||
print('%s: unable to run `%s`: %s' % (__file__, cmd, e), file=sys.stderr)
|
|
||||||
print('%s: Try installing pytest: sudo apt-get install python-pytest' %
|
# Hopefully this is a Python 3 version.
|
||||||
(__file__,), file=sys.stderr)
|
ret = shutil.which('pytest')
|
||||||
return 127
|
if ret:
|
||||||
else:
|
return ret
|
||||||
raise
|
|
||||||
|
print(f'{__file__}: unable to find pytest.', file=sys.stderr)
|
||||||
|
print(f'{__file__}: Try installing: sudo apt-get install python-pytest',
|
||||||
|
file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
@ -48,7 +52,8 @@ def main(argv):
|
|||||||
pythonpath += os.pathsep + oldpythonpath
|
pythonpath += os.pathsep + oldpythonpath
|
||||||
os.environ['PYTHONPATH'] = pythonpath
|
os.environ['PYTHONPATH'] = pythonpath
|
||||||
|
|
||||||
return run_pytest('pytest', argv)
|
pytest = find_pytest()
|
||||||
|
return subprocess.run([pytest] + argv, check=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user