Skip to content

Commit 6cd5304

Browse files
committed
Add _mypy_results
1 parent 2120ff1 commit 6cd5304

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/pytest_mypy.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Mypy static type checker plugin for Pytest"""
22

3+
import functools
34
import json
45
import os
56
from tempfile import NamedTemporaryFile
@@ -115,21 +116,7 @@ class MypyFileItem(MypyItem, pytest.File):
115116

116117
def runtest(self):
117118
"""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)
133120
abspath = os.path.abspath(str(self.fspath))
134121
errors = results['abspath_errors'].get(abspath)
135122
if errors:
@@ -144,6 +131,25 @@ def reportinfo(self):
144131
)
145132

146133

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+
147153
def _cached_json_results(results_path, results_factory=None):
148154
"""
149155
Read results from results_path if it exists;

0 commit comments

Comments
 (0)