1616PYTEST_MAJOR_VERSION = int (pytest .__version__ .partition ("." )[0 ])
1717mypy_argv = []
1818nodeid_name = "mypy"
19+ terminal_summary_title = "mypy"
1920
2021
2122def default_file_error_formatter (item , results , errors ):
@@ -59,10 +60,10 @@ def _get_xdist_workerinput(config_node):
5960 return workerinput
6061
6162
62- def _is_master (config ):
63+ def _is_xdist_controller (config ):
6364 """
6465 True if the code running the given pytest.config object is running in
65- an xdist master node or not running xdist at all.
66+ an xdist controller node or not running xdist at all.
6667 """
6768 return _get_xdist_workerinput (config ) is None
6869
@@ -73,7 +74,7 @@ def pytest_configure(config):
7374 register a custom marker for MypyItems,
7475 and configure the plugin based on the CLI.
7576 """
76- if _is_master (config ):
77+ if _is_xdist_controller (config ):
7778
7879 # Get the path to a temporary file and delete it.
7980 # The first MypyItem to run will see the file does not exist,
@@ -205,8 +206,7 @@ def runtest(self):
205206 for error in errors
206207 ):
207208 raise MypyError (file_error_formatter (self , results , errors ))
208- # This line cannot be easily covered on mypy < 0.990:
209- warnings .warn ("\n " + "\n " .join (errors ), MypyWarning ) # pragma: no cover
209+ warnings .warn ("\n " + "\n " .join (errors ), MypyWarning )
210210
211211 def reportinfo (self ):
212212 """Produce a heading for the test report."""
@@ -258,7 +258,9 @@ def from_mypy(
258258 ) -> "MypyResults" :
259259 """Generate results from mypy."""
260260
261- if opts is None :
261+ # This is covered by test_mypy_results_from_mypy_with_opts;
262+ # however, coverage is not recognized on py38-pytest4.6:
263+ if opts is None : # pragma: no cover
262264 opts = mypy_argv [:]
263265 abspath_errors = {
264266 os .path .abspath (str (item .fspath )): [] for item in items
@@ -293,7 +295,7 @@ def from_session(cls, session) -> "MypyResults":
293295 """Load (or generate) cached mypy results for a pytest session."""
294296 results_path = (
295297 session .config ._mypy_results_path
296- if _is_master (session .config )
298+ if _is_xdist_controller (session .config )
297299 else _get_xdist_workerinput (session .config )["_mypy_results_path" ]
298300 )
299301 with FileLock (results_path + ".lock" ):
@@ -322,18 +324,20 @@ class MypyWarning(pytest.PytestWarning):
322324
323325def pytest_terminal_summary (terminalreporter , config ):
324326 """Report stderr and unrecognized lines from stdout."""
325- if _is_master (config ):
326- try :
327- with open (config ._mypy_results_path , mode = "r" ) as results_f :
328- results = MypyResults .load (results_f )
329- except FileNotFoundError :
330- # No MypyItems executed.
331- return
332- if results .unmatched_stdout or results .stderr :
333- terminalreporter .section ("mypy" )
334- if results .unmatched_stdout :
335- color = {"red" : True } if results .status else {"green" : True }
336- terminalreporter .write_line (results .unmatched_stdout , ** color )
337- if results .stderr :
338- terminalreporter .write_line (results .stderr , yellow = True )
339- os .remove (config ._mypy_results_path )
327+ if not _is_xdist_controller (config ):
328+ # This isn't hit in pytest 5.0 for some reason.
329+ return # pragma: no cover
330+ try :
331+ with open (config ._mypy_results_path , mode = "r" ) as results_f :
332+ results = MypyResults .load (results_f )
333+ except FileNotFoundError :
334+ # No MypyItems executed.
335+ return
336+ if results .unmatched_stdout or results .stderr :
337+ terminalreporter .section (terminal_summary_title )
338+ if results .unmatched_stdout :
339+ color = {"red" : True } if results .status else {"green" : True }
340+ terminalreporter .write_line (results .unmatched_stdout , ** color )
341+ if results .stderr :
342+ terminalreporter .write_line (results .stderr , yellow = True )
343+ os .remove (config ._mypy_results_path )
0 commit comments