Skip to content

Commit 0845787

Browse files
committed
fix(tests): Adapt DaemonSuite to handle new pretty default
This commit adapts the `DaemonSuite` test runner and its corresponding data files to accommodate the new pretty-by-default behavior. This fix is nuanced due to the stateful, client-server nature of the daemon and required a two-part approach: 1. **Central Logic:** The `run_cmd` helper in `mypy/test/testdaemon.py` was modified to inject `--no-pretty` only into state-setting subcommands (`run`, `check`). This handles the majority of daemon tests. 2. **Manual Overrides:** A number of test cases in `daemon.test` were manually updated. This was necessary for tests that start the daemon with `dmypy start` or have other unique requirements, ensuring the server is correctly configured in non-pretty mode from the outset. This combined strategy ensures the entire daemon test suite passes. Part of #19108.
1 parent f51f469 commit 0845787

File tree

2 files changed

+124
-111
lines changed

2 files changed

+124
-111
lines changed

mypy/test/testdaemon.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ def parse_script(input: list[str]) -> list[list[str]]:
7979
def run_cmd(input: str) -> tuple[int, str]:
8080
if input[1:].startswith("mypy run --") and "--show-error-codes" not in input:
8181
input += " --hide-error-codes"
82+
is_pretty_test = "# NO-MODIFY" in input
83+
modified_input = input.replace('# NO-MODIFY', '').strip()
84+
cond1 = '--pretty' not in modified_input
85+
cond2 = modified_input.startswith("dmypy run") or \
86+
modified_input.startswith("dmypy check ")
87+
cond3 = not is_pretty_test
88+
if cond1 and cond2 and cond3:
89+
parts = modified_input.split(' ', 2)
90+
command, subcommand = parts[0], parts[1]
91+
args = parts[2] if len(parts) > 2 else ""
92+
input = f"{command} {subcommand} {args} --no-pretty".strip()
93+
else:
94+
input = modified_input
8295
if input.startswith("dmypy "):
8396
input = sys.executable + " -m mypy." + input
8497
if input.startswith("mypy "):

0 commit comments

Comments
 (0)