Open
Description
For smaller number of tests, setting up 12 workers in 12 cores in my machine is overkill, is there a way to have pytest run xdist/parallel testing only if the number of tests collected is more than 20?
I tried something like below - but it seems the workers spin up before the test collection starts
conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption(
"--min-tests-count-for-parallel",
action="store",
default=10,
type=int,
help="Min number of tests that should be collected before running tests in parallel",
)
def pytest_configure(config):
min_tests_count_for_parallel = config.getoption("--min-tests-count-for-parallel")
config.num_tests_collected = 0
config.min_tests_count_for_parallel = min_tests_count_for_parallel
def pytest_collection_modifyitems(config, items):
if len(items) > config.min_tests_count_for_parallel:
config.option.numprocesses = "auto"
else:
config.option.numprocesses = 0
@pytest.hookimpl(tryfirst=True)
def pytest_cmdline_preparse(config, args):
if "-n" in args:
args.remove("-n")
Metadata
Metadata
Assignees
Labels
No labels