Browse Source

unit tests: Check whether pytest-xdist is available

Also, always run pytest using the module format to ensure that we're
always using the Python interpreter selected by the user.

Fixes issue reported in https://github.com/mesonbuild/meson/pull/5621#issuecomment-513034198
Nirbheek Chauhan 4 months ago
parent
commit
4200afc74d
1 changed files with 4 additions and 5 deletions
  1. 4
    5
      run_unittests.py

+ 4
- 5
run_unittests.py View File

@@ -6599,15 +6599,14 @@ def unset_envs():
6599 6599
 
6600 6600
 def main():
6601 6601
     unset_envs()
6602
-    pytest_args = ['-n', 'auto', './run_unittests.py']
6603
-    if shutil.which('pytest-3'):
6604
-        return subprocess.run(['pytest-3'] + pytest_args).returncode
6605
-    elif shutil.which('pytest'):
6606
-        return subprocess.run(['pytest'] + pytest_args).returncode
6607 6602
     try:
6608 6603
         import pytest # noqa: F401
6604
+        # Need pytest-xdist for `-n` arg
6605
+        import xdist # noqa: F401
6606
+        pytest_args = ['-n', 'auto', './run_unittests.py']
6609 6607
         return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode
6610 6608
     except ImportError:
6609
+        print('pytest-xdist not found, using unittest instead')
6611 6610
         pass
6612 6611
     # All attempts at locating pytest failed, fall back to plain unittest.
6613 6612
     cases = ['InternalTests', 'DataTests', 'AllPlatformTests', 'FailureTests',

Loading…
Cancel
Save