Skip to content

Commit 38a7104

Browse files
authored
tests: --update-data incompatible with xdist (#15641)
Fixes a [gotcha](#15283 (comment)) with `--update-data`. When using `--update-data` with parallelized tests (xdist), the line offsets determined at test time may become wrong by update time, as multiple workers perform their updates to the same file. This makes it so we exit with a usage error when `--update-data` is used with parallelism.
1 parent 569cfc9 commit 38a7104

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mypy/test/data.py

+7
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ def pytest_addoption(parser: Any) -> None:
621621
)
622622

623623

624+
def pytest_configure(config: pytest.Config) -> None:
625+
if config.getoption("--update-data") and config.getoption("--numprocesses", default=1) > 1:
626+
raise pytest.UsageError(
627+
"--update-data incompatible with parallelized tests; re-run with -n 1"
628+
)
629+
630+
624631
# This function name is special to pytest. See
625632
# https://doc.pytest.org/en/latest/how-to/writing_plugins.html#collection-hooks
626633
def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> Any | None:

0 commit comments

Comments
 (0)