@@ -90,6 +90,7 @@ def pytest_configure(config):
90
90
and configure the plugin based on the CLI.
91
91
"""
92
92
if _is_xdist_controller (config ):
93
+ config .pluginmanager .register (MypyReportingPlugin ())
93
94
94
95
# Get the path to a temporary file and delete it.
95
96
# The first MypyItem to run will see the file does not exist,
@@ -313,22 +314,23 @@ class MypyWarning(pytest.PytestWarning):
313
314
"""A non-failure message regarding the mypy run."""
314
315
315
316
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