mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
tests: Rework run_tests to use pytest directly and add vpython3 file
Remove logic to handle importing the right version of pytest. './run_tests' still works but this allows presubmit builders to test using 'vpython3 ./run_tests'. Google-Bug-Id: b/266734831 Change-Id: I6a543c1f4b5b4449e723095b4a70e5228b1ccd34 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/356717 Tested-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Josip Sokcevic <sokcevic@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
42
run_tests
42
run_tests
@ -15,46 +15,8 @@
|
||||
|
||||
"""Wrapper to run pytest with the right settings."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def find_pytest():
|
||||
"""Try to locate a good version of pytest."""
|
||||
# If we're in a virtualenv, assume that it's provided the right pytest.
|
||||
if 'VIRTUAL_ENV' in os.environ:
|
||||
return 'pytest'
|
||||
|
||||
# Use the Python 3 version if available.
|
||||
ret = shutil.which('pytest-3')
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
# Hopefully this is a Python 3 version.
|
||||
ret = shutil.which('pytest')
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
print('%s: unable to find pytest.' % (__file__,), file=sys.stderr)
|
||||
print('%s: Try installing: sudo apt-get install python-pytest' % (__file__,),
|
||||
file=sys.stderr)
|
||||
|
||||
|
||||
def main(argv):
|
||||
"""The main entry."""
|
||||
# Add the repo tree to PYTHONPATH as the tests expect to be able to import
|
||||
# modules directly.
|
||||
pythonpath = os.path.dirname(os.path.realpath(__file__))
|
||||
oldpythonpath = os.environ.get('PYTHONPATH', None)
|
||||
if oldpythonpath is not None:
|
||||
pythonpath += os.pathsep + oldpythonpath
|
||||
os.environ['PYTHONPATH'] = pythonpath
|
||||
|
||||
pytest = find_pytest()
|
||||
return subprocess.run([pytest] + argv, check=False).returncode
|
||||
|
||||
import pytest
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
sys.exit(pytest.main(sys.argv[1:]))
|
||||
|
Reference in New Issue
Block a user