From c55a9ea8d93643affa11ea2ab1f4ca4cdd7c1ad7 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Fri, 6 Sep 2024 00:09:49 -0700 Subject: [PATCH 1/2] Replace MypyReportingPlugin with MypyControllerPlugin --- src/pytest_mypy/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pytest_mypy/__init__.py b/src/pytest_mypy/__init__.py index 73bd12f..fa016b5 100644 --- a/src/pytest_mypy/__init__.py +++ b/src/pytest_mypy/__init__.py @@ -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, @@ -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: From 97e8f4108ce4fe21f59f4cd00df2a8ef85c206de Mon Sep 17 00:00:00 2001 From: David Tucker Date: Fri, 6 Sep 2024 00:10:21 -0700 Subject: [PATCH 2/2] Move results path cleanup to pytest_unconfigure --- src/pytest_mypy/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pytest_mypy/__init__.py b/src/pytest_mypy/__init__.py index fa016b5..699a900 100644 --- a/src/pytest_mypy/__init__.py +++ b/src/pytest_mypy/__init__.py @@ -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