Skip to content

Commit

Permalink
Merge pull request #181 from dmtucker/unconfigure
Browse files Browse the repository at this point in the history
Move results path cleanup to pytest_unconfigure
  • Loading branch information
dmtucker authored Sep 18, 2024
2 parents 34a215c + 97e8f41 commit e84607e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/pytest_mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def pytest_configure(config: pytest.Config) -> None:
"""
xdist_worker = _xdist_worker(config)
if not xdist_worker:
config.pluginmanager.register(MypyReportingPlugin())
config.pluginmanager.register(MypyControllerPlugin())

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


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

def pytest_terminal_summary(
self,
terminalreporter: TerminalReporter,
config: pytest.Config,
) -> None:
"""Report stderr and unrecognized lines from stdout."""
"""Report mypy results."""
mypy_results_path = config.stash[stash_key["config"]].mypy_results_path
try:
with open(mypy_results_path, mode="r") as results_f:
Expand All @@ -397,4 +397,11 @@ def pytest_terminal_summary(
terminalreporter.write_line(results.unmatched_stdout, **color)
if results.stderr:
terminalreporter.write_line(results.stderr, yellow=True)
mypy_results_path.unlink()

def pytest_unconfigure(self, config: pytest.Config) -> None:
"""Clean up the mypy results path."""
try:
config.stash[stash_key["config"]].mypy_results_path.unlink()
except FileNotFoundError: # compat python < 3.8 (missing_ok=True)
# No MypyItems executed.
return

0 comments on commit e84607e

Please sign in to comment.