From 3ed84466f4e8548a7667e81d99ad7161bd7d9489 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 25 Jan 2023 21:19:54 +0000 Subject: [PATCH] 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 Reviewed-by: Josip Sokcevic Reviewed-by: Mike Frysinger --- run_tests | 42 ++----------------------------- run_tests.vpython3 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 run_tests.vpython3 diff --git a/run_tests b/run_tests index 5de51cf0..0ea098a6 100755 --- a/run_tests +++ b/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:])) diff --git a/run_tests.vpython3 b/run_tests.vpython3 new file mode 100644 index 00000000..d0e821dd --- /dev/null +++ b/run_tests.vpython3 @@ -0,0 +1,61 @@ +# This is a vpython "spec" file. +# +# Read more about `vpython` and how to modify this file here: +# https://chromium.googlesource.com/infra/infra/+/main/doc/users/vpython.md +# List of available wheels: +# https://chromium.googlesource.com/infra/infra/+/main/infra/tools/dockerbuild/wheels.md + +python_version: "3.8" + +wheel: < + name: "infra/python/wheels/pytest-py3" + version: "version:6.2.2" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/py-py2_py3" + version: "version:1.10.0" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/iniconfig-py3" + version: "version:1.1.1" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/packaging-py2_py3" + version: "version:16.8" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/pluggy-py3" + version: "version:0.13.1" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/toml-py3" + version: "version:0.10.1" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/pyparsing-py3" + version: "version:3.0.7" +> + +# Required by pytest==6.2.2 +wheel: < + name: "infra/python/wheels/attrs-py2_py3" + version: "version:21.4.0" +> + +# Required by packaging==16.8 +wheel: < + name: "infra/python/wheels/six-py2_py3" + version: "version:1.16.0" +>