diff options
Diffstat (limited to 'run_tests')
-rwxr-xr-x | run_tests | 42 |
1 files changed, 2 insertions, 40 deletions
@@ -15,46 +15,8 @@ | |||
15 | 15 | ||
16 | """Wrapper to run pytest with the right settings.""" | 16 | """Wrapper to run pytest with the right settings.""" |
17 | 17 | ||
18 | import os | ||
19 | import shutil | ||
20 | import subprocess | ||
21 | import sys | 18 | import sys |
22 | 19 | import pytest | |
23 | |||
24 | def find_pytest(): | ||
25 | """Try to locate a good version of pytest.""" | ||
26 | # If we're in a virtualenv, assume that it's provided the right pytest. | ||
27 | if 'VIRTUAL_ENV' in os.environ: | ||
28 | return 'pytest' | ||
29 | |||
30 | # Use the Python 3 version if available. | ||
31 | ret = shutil.which('pytest-3') | ||
32 | if ret: | ||
33 | return ret | ||
34 | |||
35 | # Hopefully this is a Python 3 version. | ||
36 | ret = shutil.which('pytest') | ||
37 | if ret: | ||
38 | return ret | ||
39 | |||
40 | print('%s: unable to find pytest.' % (__file__,), file=sys.stderr) | ||
41 | print('%s: Try installing: sudo apt-get install python-pytest' % (__file__,), | ||
42 | file=sys.stderr) | ||
43 | |||
44 | |||
45 | def main(argv): | ||
46 | """The main entry.""" | ||
47 | # Add the repo tree to PYTHONPATH as the tests expect to be able to import | ||
48 | # modules directly. | ||
49 | pythonpath = os.path.dirname(os.path.realpath(__file__)) | ||
50 | oldpythonpath = os.environ.get('PYTHONPATH', None) | ||
51 | if oldpythonpath is not None: | ||
52 | pythonpath += os.pathsep + oldpythonpath | ||
53 | os.environ['PYTHONPATH'] = pythonpath | ||
54 | |||
55 | pytest = find_pytest() | ||
56 | return subprocess.run([pytest] + argv, check=False).returncode | ||
57 | |||
58 | 20 | ||
59 | if __name__ == '__main__': | 21 | if __name__ == '__main__': |
60 | sys.exit(main(sys.argv[1:])) | 22 | sys.exit(pytest.main(sys.argv[1:])) |