Skip to content

Commit 1b3e931

Browse files
authored
Merge pull request #195 from dmtucker/issue194
Catch OSErrors when parsing mypy error paths
2 parents 66eab40 + 93aa86d commit 1b3e931

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/pytest_mypy/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ def from_mypy(
360360
for line in stdout.split("\n"):
361361
if not line:
362362
continue
363-
path = Path(line.partition(":")[0]).resolve()
363+
try:
364+
path = Path(line.partition(":")[0]).resolve()
365+
except OSError:
366+
path = None
364367
try:
365368
lines = path_lines[path]
366369
except KeyError:

tests/test_pytest_mypy.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,34 @@ def pyfunc(x: int) -> str:
138138
assert result.ret == pytest.ExitCode.TESTS_FAILED
139139

140140

141-
def test_mypy_annotation_unchecked(testdir, xdist_args, tmp_path, monkeypatch):
141+
def test_mypy_path_error(testdir, xdist_args):
142+
"""Verify that runs are not affected by path errors."""
143+
testdir.makepyfile(
144+
conftest="""
145+
def pytest_configure(config):
146+
plugin = config.pluginmanager.getplugin('mypy')
147+
148+
class FakePath:
149+
def __init__(self, _):
150+
pass
151+
def resolve(self):
152+
raise OSError
153+
154+
Path = plugin.Path
155+
plugin.Path = FakePath
156+
plugin.MypyResults.from_mypy([], opts=['--version'])
157+
plugin.Path = Path
158+
""",
159+
)
160+
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
161+
mypy_file_checks = 1
162+
mypy_status_check = 1
163+
mypy_checks = mypy_file_checks + mypy_status_check
164+
result.assert_outcomes(passed=mypy_checks)
165+
assert result.ret == pytest.ExitCode.OK
166+
167+
168+
def test_mypy_annotation_unchecked(testdir, xdist_args, tmp_path):
142169
"""Verify that annotation-unchecked warnings do not manifest as an error."""
143170
testdir.makepyfile(
144171
"""

0 commit comments

Comments
 (0)