Skip to content

Commit

Permalink
tests: --update-data incompatible with xdist (#15641)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ikonst authored Jul 12, 2023
1 parent 569cfc9 commit 38a7104
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ def pytest_addoption(parser: Any) -> None:
)


def pytest_configure(config: pytest.Config) -> None:
if config.getoption("--update-data") and config.getoption("--numprocesses", default=1) > 1:
raise pytest.UsageError(
"--update-data incompatible with parallelized tests; re-run with -n 1"
)


# This function name is special to pytest. See
# https://doc.pytest.org/en/latest/how-to/writing_plugins.html#collection-hooks
def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> Any | None:
Expand Down

0 comments on commit 38a7104

Please sign in to comment.