Skip to content

Commit e84607e

Browse files
authored
Merge pull request #181 from dmtucker/unconfigure
Move results path cleanup to pytest_unconfigure
2 parents 34a215c + 97e8f41 commit e84607e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/pytest_mypy/__init__.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def pytest_configure(config: pytest.Config) -> None:
130130
"""
131131
xdist_worker = _xdist_worker(config)
132132
if not xdist_worker:
133-
config.pluginmanager.register(MypyReportingPlugin())
133+
config.pluginmanager.register(MypyControllerPlugin())
134134

135135
# Get the path to a temporary file and delete it.
136136
# The first MypyItem to run will see the file does not exist,
@@ -372,15 +372,15 @@ class MypyWarning(pytest.PytestWarning):
372372
"""A non-failure message regarding the mypy run."""
373373

374374

375-
class MypyReportingPlugin:
376-
"""A Pytest plugin that reports mypy results."""
375+
class MypyControllerPlugin:
376+
"""A plugin that is not registered on xdist worker processes."""
377377

378378
def pytest_terminal_summary(
379379
self,
380380
terminalreporter: TerminalReporter,
381381
config: pytest.Config,
382382
) -> None:
383-
"""Report stderr and unrecognized lines from stdout."""
383+
"""Report mypy results."""
384384
mypy_results_path = config.stash[stash_key["config"]].mypy_results_path
385385
try:
386386
with open(mypy_results_path, mode="r") as results_f:
@@ -397,4 +397,11 @@ def pytest_terminal_summary(
397397
terminalreporter.write_line(results.unmatched_stdout, **color)
398398
if results.stderr:
399399
terminalreporter.write_line(results.stderr, yellow=True)
400-
mypy_results_path.unlink()
400+
401+
def pytest_unconfigure(self, config: pytest.Config) -> None:
402+
"""Clean up the mypy results path."""
403+
try:
404+
config.stash[stash_key["config"]].mypy_results_path.unlink()
405+
except FileNotFoundError: # compat python < 3.8 (missing_ok=True)
406+
# No MypyItems executed.
407+
return

0 commit comments

Comments
 (0)