1
1
"""Mypy static type checker plugin for Pytest"""
2
2
3
+ import functools
3
4
import json
4
5
import os
5
6
from tempfile import NamedTemporaryFile
@@ -115,21 +116,7 @@ class MypyFileItem(MypyItem, pytest.File):
115
116
116
117
def runtest (self ):
117
118
"""Raise an exception if mypy found errors for this item."""
118
- results = _cached_json_results (
119
- results_path = (
120
- self .config ._mypy_results_path
121
- if _is_master (self .config ) else
122
- self .config .slaveinput ['_mypy_results_path' ]
123
- ),
124
- results_factory = lambda :
125
- _mypy_results_factory (
126
- abspaths = [
127
- os .path .abspath (str (item .fspath ))
128
- for item in self .session .items
129
- if isinstance (item , MypyFileItem )
130
- ],
131
- )
132
- )
119
+ results = _mypy_results (self .session )
133
120
abspath = os .path .abspath (str (self .fspath ))
134
121
errors = results ['abspath_errors' ].get (abspath )
135
122
if errors :
@@ -144,6 +131,25 @@ def reportinfo(self):
144
131
)
145
132
146
133
134
+ def _mypy_results (session ):
135
+ """Get the cached mypy results for the session, or generate them."""
136
+ return _cached_json_results (
137
+ results_path = (
138
+ session .config ._mypy_results_path
139
+ if _is_master (session .config ) else
140
+ session .config .slaveinput ['_mypy_results_path' ]
141
+ ),
142
+ results_factory = functools .partial (
143
+ _mypy_results_factory ,
144
+ abspaths = [
145
+ os .path .abspath (str (item .fspath ))
146
+ for item in session .items
147
+ if isinstance (item , MypyFileItem )
148
+ ],
149
+ )
150
+ )
151
+
152
+
147
153
def _cached_json_results (results_path , results_factory = None ):
148
154
"""
149
155
Read results from results_path if it exists;
0 commit comments