Skip to content

Commit 8a5fedc

Browse files
committed
Populate the config stash on xdist workers
1 parent b577d9d commit 8a5fedc

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/pytest_mypy.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def pytest_configure(config):
8989
register a custom marker for MypyItems,
9090
and configure the plugin based on the CLI.
9191
"""
92-
if not _xdist_worker(config):
92+
xdist_worker = _xdist_worker(config)
93+
if not xdist_worker:
9394
config.pluginmanager.register(MypyReportingPlugin())
9495

9596
# Get the path to a temporary file and delete it.
@@ -106,6 +107,11 @@ def pytest_configure(config):
106107
# the workers so that they know where to read parsed results from.
107108
if config.pluginmanager.getplugin("xdist"):
108109
config.pluginmanager.register(MypyXdistControllerPlugin())
110+
else:
111+
# xdist workers create the stash using input from the controller plugin.
112+
config.stash[stash_key["config"]] = MypyConfigStash.from_serialized(
113+
xdist_worker["input"]["mypy_config_stash_serialized"]
114+
)
109115

110116
config.addinivalue_line(
111117
"markers",
@@ -271,14 +277,7 @@ def from_mypy(
271277
@classmethod
272278
def from_session(cls, session) -> "MypyResults":
273279
"""Load (or generate) cached mypy results for a pytest session."""
274-
xdist_worker = _xdist_worker(session.config)
275-
if not xdist_worker:
276-
mypy_config_stash = session.config.stash[stash_key["config"]]
277-
else:
278-
mypy_config_stash = MypyConfigStash.from_serialized(
279-
xdist_worker["input"]["mypy_config_stash_serialized"]
280-
)
281-
mypy_results_path = mypy_config_stash.mypy_results_path
280+
mypy_results_path = session.config.stash[stash_key["config"]].mypy_results_path
282281
with FileLock(str(mypy_results_path) + ".lock"):
283282
try:
284283
with open(mypy_results_path, mode="r") as results_f:

tests/test_pytest_mypy.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,10 @@ def test_mypy_no_output(testdir, xdist_args):
518518
conftest="""
519519
import pytest
520520
521-
@pytest.hookimpl(hookwrapper=True)
522-
def pytest_terminal_summary(config):
521+
@pytest.hookimpl(trylast=True)
522+
def pytest_configure(config):
523523
pytest_mypy = config.pluginmanager.getplugin("mypy")
524-
try:
525-
mypy_config_stash = config.stash[pytest_mypy.stash_key["config"]]
526-
except KeyError:
527-
# xdist worker
528-
return
524+
mypy_config_stash = config.stash[pytest_mypy.stash_key["config"]]
529525
with open(mypy_config_stash.mypy_results_path, mode="w") as results_f:
530526
pytest_mypy.MypyResults(
531527
opts=[],
@@ -535,7 +531,6 @@ def pytest_terminal_summary(config):
535531
abspath_errors={},
536532
unmatched_stdout="",
537533
).dump(results_f)
538-
yield
539534
""",
540535
)
541536
result = testdir.runpytest_subprocess("--mypy", *xdist_args)

0 commit comments

Comments
 (0)