16
16
PYTEST_MAJOR_VERSION = int (pytest .__version__ .partition ("." )[0 ])
17
17
mypy_argv = []
18
18
nodeid_name = "mypy"
19
+ terminal_summary_title = "mypy"
19
20
20
21
21
22
def default_file_error_formatter (item , results , errors ):
@@ -59,10 +60,10 @@ def _get_xdist_workerinput(config_node):
59
60
return workerinput
60
61
61
62
62
- def _is_master (config ):
63
+ def _is_xdist_controller (config ):
63
64
"""
64
65
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.
66
67
"""
67
68
return _get_xdist_workerinput (config ) is None
68
69
@@ -73,7 +74,7 @@ def pytest_configure(config):
73
74
register a custom marker for MypyItems,
74
75
and configure the plugin based on the CLI.
75
76
"""
76
- if _is_master (config ):
77
+ if _is_xdist_controller (config ):
77
78
78
79
# Get the path to a temporary file and delete it.
79
80
# The first MypyItem to run will see the file does not exist,
@@ -205,8 +206,7 @@ def runtest(self):
205
206
for error in errors
206
207
):
207
208
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 )
210
210
211
211
def reportinfo (self ):
212
212
"""Produce a heading for the test report."""
@@ -258,7 +258,9 @@ def from_mypy(
258
258
) -> "MypyResults" :
259
259
"""Generate results from mypy."""
260
260
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
262
264
opts = mypy_argv [:]
263
265
abspath_errors = {
264
266
os .path .abspath (str (item .fspath )): [] for item in items
@@ -293,7 +295,7 @@ def from_session(cls, session) -> "MypyResults":
293
295
"""Load (or generate) cached mypy results for a pytest session."""
294
296
results_path = (
295
297
session .config ._mypy_results_path
296
- if _is_master (session .config )
298
+ if _is_xdist_controller (session .config )
297
299
else _get_xdist_workerinput (session .config )["_mypy_results_path" ]
298
300
)
299
301
with FileLock (results_path + ".lock" ):
@@ -322,18 +324,20 @@ class MypyWarning(pytest.PytestWarning):
322
324
323
325
def pytest_terminal_summary (terminalreporter , config ):
324
326
"""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