Skip to content

Commit 99dd314

Browse files
authored
Automatically set -n=0 when running tests with --update-data (#17204)
Unless there is a reason to have the error, I think this improves the developer experience.
1 parent 42157ba commit 99dd314

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

mypy/test/data.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,13 @@ def pytest_addoption(parser: Any) -> None:
620620
)
621621

622622

623-
def pytest_configure(config: pytest.Config) -> None:
624-
if config.getoption("--update-data") and config.getoption("--numprocesses", default=1) > 1:
625-
raise pytest.UsageError(
626-
"--update-data incompatible with parallelized tests; re-run with -n 1"
627-
)
623+
@pytest.hookimpl(tryfirst=True)
624+
def pytest_cmdline_main(config: pytest.Config) -> None:
625+
if config.getoption("--collectonly"):
626+
return
627+
# --update-data is not compatible with parallelized tests, disable parallelization
628+
if config.getoption("--update-data"):
629+
config.option.numprocesses = 0
628630

629631

630632
# This function name is special to pytest. See

mypy/test/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def assert_string_arrays_equal(
135135
show_align_message(expected[first_diff], actual[first_diff])
136136

137137
sys.stderr.write(
138-
"Update the test output using --update-data -n0 "
139-
"(you can additionally use the -k selector to update only specific tests)\n"
138+
"Update the test output using --update-data "
139+
"(implies -n0; you can additionally use the -k selector to update only specific tests)\n"
140140
)
141141
pytest.fail(msg, pytrace=traceback)
142142

0 commit comments

Comments
 (0)