Skip to content

Commit 8008632

Browse files
committed
Create MypyReportingPlugin
1 parent 282e0a6 commit 8008632

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/pytest_mypy.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def pytest_configure(config):
9090
and configure the plugin based on the CLI.
9191
"""
9292
if _is_xdist_controller(config):
93+
config.pluginmanager.register(MypyReportingPlugin())
9394

9495
# Get the path to a temporary file and delete it.
9596
# The first MypyItem to run will see the file does not exist,
@@ -313,22 +314,23 @@ class MypyWarning(pytest.PytestWarning):
313314
"""A non-failure message regarding the mypy run."""
314315

315316

316-
def pytest_terminal_summary(terminalreporter, config):
317-
"""Report stderr and unrecognized lines from stdout."""
318-
if not _is_xdist_controller(config):
319-
return
320-
mypy_results_path = config.stash[stash_key["config"]].mypy_results_path
321-
try:
322-
with open(mypy_results_path, mode="r") as results_f:
323-
results = MypyResults.load(results_f)
324-
except FileNotFoundError:
325-
# No MypyItems executed.
326-
return
327-
if results.unmatched_stdout or results.stderr:
328-
terminalreporter.section(terminal_summary_title)
329-
if results.unmatched_stdout:
330-
color = {"red": True} if results.status else {"green": True}
331-
terminalreporter.write_line(results.unmatched_stdout, **color)
332-
if results.stderr:
333-
terminalreporter.write_line(results.stderr, yellow=True)
334-
mypy_results_path.unlink()
317+
class MypyReportingPlugin:
318+
"""A Pytest plugin that reports mypy results."""
319+
320+
def pytest_terminal_summary(self, terminalreporter, config):
321+
"""Report stderr and unrecognized lines from stdout."""
322+
mypy_results_path = config.stash[stash_key["config"]].mypy_results_path
323+
try:
324+
with open(mypy_results_path, mode="r") as results_f:
325+
results = MypyResults.load(results_f)
326+
except FileNotFoundError:
327+
# No MypyItems executed.
328+
return
329+
if results.unmatched_stdout or results.stderr:
330+
terminalreporter.section(terminal_summary_title)
331+
if results.unmatched_stdout:
332+
color = {"red": True} if results.status else {"green": True}
333+
terminalreporter.write_line(results.unmatched_stdout, **color)
334+
if results.stderr:
335+
terminalreporter.write_line(results.stderr, yellow=True)
336+
mypy_results_path.unlink()

0 commit comments

Comments
 (0)