diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-09-10 13:10:40 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-09-10 13:10:40 +0530 |
commit | cb43bc300c25b6e760378d19cdce090d986a6650 (patch) | |
tree | cd31a91ebc2749882eef0fd6056fc841682fd14a | |
parent | 8e90c0ee0034bba2f5b434ee32d5a8b3a48c2096 (diff) | |
download | meson-nirbheek/fix-windows-cross-compile.tar.gz |
unit tests: Don't use pytest-xdist when running a single testnirbheek/fix-windows-cross-compile
-rwxr-xr-x | run_unittests.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/run_unittests.py b/run_unittests.py index b76e4894d..50dc76b96 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -9008,18 +9008,16 @@ def convert_args(argv): pytest_args += ['-k', ' or '.join(test_list)] return pytest_args +def running_a_single_test(argv, cases): + 'Check whether we got an argument for running an individual test' + for arg in argv: + for case in cases: + if arg.startswith(case) and '.' in arg and case in arg.split('.'): + return True + return False + def main(): unset_envs() - try: - import pytest # noqa: F401 - # Need pytest-xdist for `-n` arg - import xdist # noqa: F401 - pytest_args = ['-n', 'auto', './run_unittests.py'] - pytest_args += convert_args(sys.argv[1:]) - return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode - except ImportError: - print('pytest-xdist not found, using unittest instead') - # All attempts at locating pytest failed, fall back to plain unittest. cases = ['InternalTests', 'DataTests', 'AllPlatformTests', 'FailureTests', 'PythonTests', 'NativeFileTests', 'RewriterTests', 'CrossFileTests', 'TAPParserTests', @@ -9027,6 +9025,19 @@ def main(): 'LinuxlikeTests', 'LinuxCrossArmTests', 'LinuxCrossMingwTests', 'WindowsTests', 'DarwinTests'] + # Don't use pytest-xdist when running a single unit test since it wastes + # time spawning a lot of processes to distribute tests to, just for one job + if not running_a_single_test(sys.argv, cases): + try: + import pytest # noqa: F401 + # Need pytest-xdist for `-n` arg + import xdist # noqa: F401 + pytest_args = ['-n', 'auto', './run_unittests.py'] + pytest_args += convert_args(sys.argv[1:]) + return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode + except ImportError: + print('pytest-xdist not found, using unittest instead') + # Fallback to plain unittest. return unittest.main(defaultTest=cases, buffer=True) if __name__ == '__main__': |