14
14
15
15
mypy_argv = []
16
16
nodeid_name = "mypy"
17
+ stash_keys = {
18
+ "mypy_results_path" : pytest .StashKey [Path ](),
19
+ }
17
20
terminal_summary_title = "mypy"
18
21
19
22
@@ -80,18 +83,18 @@ def pytest_configure(config):
80
83
# Subsequent MypyItems will see the file exists,
81
84
# and they will read the parsed results.
82
85
with NamedTemporaryFile (delete = True ) as tmp_f :
83
- config ._mypy_results_path = tmp_f .name
86
+ config .stash [ stash_keys [ "mypy_results_path" ]] = Path ( tmp_f .name )
84
87
85
88
# If xdist is enabled, then the results path should be exposed to
86
89
# the workers so that they know where to read parsed results from.
87
90
if config .pluginmanager .getplugin ("xdist" ):
88
91
89
92
class _MypyXdistPlugin :
90
93
def pytest_configure_node (self , node ): # xdist hook
91
- """Pass config._mypy_results_path to workers."""
92
- _get_xdist_workerinput (node )[
93
- "_mypy_results_path"
94
- ] = node . config . _mypy_results_path
94
+ """Pass the mypy results path to workers."""
95
+ _get_xdist_workerinput (node )["_mypy_results_path" ] = str (
96
+ node . config . stash [ stash_keys [ "mypy_results_path" ]]
97
+ )
95
98
96
99
config .pluginmanager .register (_MypyXdistPlugin ())
97
100
@@ -259,14 +262,14 @@ def from_mypy(
259
262
@classmethod
260
263
def from_session (cls , session ) -> "MypyResults" :
261
264
"""Load (or generate) cached mypy results for a pytest session."""
262
- results_path = (
263
- session .config ._mypy_results_path
265
+ mypy_results_path = Path (
266
+ session .config .stash [ stash_keys [ "mypy_results_path" ]]
264
267
if _is_xdist_controller (session .config )
265
268
else _get_xdist_workerinput (session .config )["_mypy_results_path" ]
266
269
)
267
- with FileLock (results_path + ".lock" ):
270
+ with FileLock (str ( mypy_results_path ) + ".lock" ):
268
271
try :
269
- with open (results_path , mode = "r" ) as results_f :
272
+ with open (mypy_results_path , mode = "r" ) as results_f :
270
273
results = cls .load (results_f )
271
274
except FileNotFoundError :
272
275
results = cls .from_mypy (
@@ -276,7 +279,7 @@ def from_session(cls, session) -> "MypyResults":
276
279
if isinstance (item , MypyFileItem )
277
280
],
278
281
)
279
- with open (results_path , mode = "w" ) as results_f :
282
+ with open (mypy_results_path , mode = "w" ) as results_f :
280
283
results .dump (results_f )
281
284
return results
282
285
@@ -296,8 +299,9 @@ def pytest_terminal_summary(terminalreporter, config):
296
299
"""Report stderr and unrecognized lines from stdout."""
297
300
if not _is_xdist_controller (config ):
298
301
return
302
+ mypy_results_path = config .stash [stash_keys ["mypy_results_path" ]]
299
303
try :
300
- with open (config . _mypy_results_path , mode = "r" ) as results_f :
304
+ with open (mypy_results_path , mode = "r" ) as results_f :
301
305
results = MypyResults .load (results_f )
302
306
except FileNotFoundError :
303
307
# No MypyItems executed.
@@ -309,4 +313,4 @@ def pytest_terminal_summary(terminalreporter, config):
309
313
terminalreporter .write_line (results .unmatched_stdout , ** color )
310
314
if results .stderr :
311
315
terminalreporter .write_line (results .stderr , yellow = True )
312
- Path ( config . _mypy_results_path ) .unlink ()
316
+ mypy_results_path .unlink ()
0 commit comments