adamant-coat-28831
09/24/2024, 4:49 PMxdist. It does not appear possible to set xdist_concurrency="auto" in a pytest target, eg:
python_tests(
name="my_tests",
sources=["test_*.py"],
resolve="main",
xdist_concurrency="auto",
)
However if you remove xdist_concurrency then you can run this successfully:
pants test test_this: -- -n auto
I wanted to confirm whether or not setting xdist_concurrency="auto" was possible or not.happy-kitchen-89482
09/25/2024, 7:14 PMint type, so yeah, auto will not be accepted. However it also looks like “If pytest-xdist is enabled and this field is unset, Pants will attempt to derive the concurrency for test sources by counting the number of tests in each file.”happy-kitchen-89482
09/25/2024, 7:15 PMhappy-kitchen-89482
09/25/2024, 7:18 PMadamant-coat-28831
09/25/2024, 7:20 PMtarget, the parallelization is invoked.
I managed to work around this by assigning nproc to an environmental variable PANTS_XDIST_CONCURRENCY and and then using that in the BUILD file:
xdist_concurrency=int(env("PANTS_XDIST_CONCURRENCY", 20)),happy-kitchen-89482
09/25/2024, 8:23 PM[pytest].xdist_enabled = True ?adamant-coat-28831
09/25/2024, 8:30 PMmelodic-knife-23027
11/01/2025, 8:44 PM_TEST_PATTERN = re.compile(b"def\\s+test_")
def _count_pytest_tests(contents: DigestContents) -> int:
return sum(len(_TEST_PATTERN.findall(file.content)) for file in contents)
So parameterized tests are counted incorrectly.happy-kitchen-89482
11/03/2025, 12:46 AM