Skip to content

Commit

Permalink
run_unittests: check for pytest and pytest-xdist separately
Browse files Browse the repository at this point in the history
Do not quit from using pytest at all, when pytest is present, simply
because xdist isn't available. Even without xdist, pytest is still
useful.

There doesn't seem to be any particular reason to require xdist. It just
happens to have been implemented that way, back in commit
4200afc when we originally added a
check to avoid pytest erroring out with unknown options when xdist
options are passed and xdist is not installed.
  • Loading branch information
eli-schwartz authored and nirbheek committed Feb 14, 2022
1 parent 4274e0f commit d37002a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ def main():

try:
import pytest # noqa: F401
# Need pytest-xdist for `-n` arg
import xdist # noqa: F401
pytest_args = []
# Don't use pytest-xdist when running single unit tests since it wastes
# time spawning a lot of processes to distribute tests to in that case.
if not running_single_tests(sys.argv, cases):
pytest_args += ['-n', 'auto']
try:
# Need pytest-xdist for `-n` arg
import xdist # noqa: F401
# Don't use pytest-xdist when running single unit tests since it wastes
# time spawning a lot of processes to distribute tests to in that case.
if not running_single_tests(sys.argv, cases):
pytest_args += ['-n', 'auto']
except ImportError:
print('pytest-xdist not found, tests will not be distributed across CPU cores')
# Let there be colors!
if 'CI' in os.environ:
pytest_args += ['--color=yes']
Expand All @@ -143,7 +146,7 @@ def main():
pass
return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode
except ImportError:
print('pytest-xdist not found, using unittest instead')
print('pytest not found, using unittest instead')
# Fallback to plain unittest.
return unittest.main(defaultTest=cases, buffer=True)

Expand Down

0 comments on commit d37002a

Please sign in to comment.