Skip to content

Commit

Permalink
Automatically set -n=0 when running tests with --update-data (#17204)
Browse files Browse the repository at this point in the history
Unless there is a reason to have the error, I think this improves the
developer experience.
  • Loading branch information
hamdanal authored May 21, 2024
1 parent 42157ba commit 99dd314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,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"
)
@pytest.hookimpl(tryfirst=True)
def pytest_cmdline_main(config: pytest.Config) -> None:
if config.getoption("--collectonly"):
return
# --update-data is not compatible with parallelized tests, disable parallelization
if config.getoption("--update-data"):
config.option.numprocesses = 0


# This function name is special to pytest. See
Expand Down
4 changes: 2 additions & 2 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def assert_string_arrays_equal(
show_align_message(expected[first_diff], actual[first_diff])

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

Expand Down

0 comments on commit 99dd314

Please sign in to comment.