Skip to content

Catch OSErrors when parsing mypy error paths #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/pytest_mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ def from_mypy(
for line in stdout.split("\n"):
if not line:
continue
path = Path(line.partition(":")[0]).resolve()
try:
path = Path(line.partition(":")[0]).resolve()
except OSError:
path = None
try:
lines = path_lines[path]
except KeyError:
Expand Down
29 changes: 28 additions & 1 deletion tests/test_pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,34 @@ def pyfunc(x: int) -> str:
assert result.ret == pytest.ExitCode.TESTS_FAILED


def test_mypy_annotation_unchecked(testdir, xdist_args, tmp_path, monkeypatch):
def test_mypy_path_error(testdir, xdist_args):
"""Verify that runs are not affected by path errors."""
testdir.makepyfile(
conftest="""
def pytest_configure(config):
plugin = config.pluginmanager.getplugin('mypy')

class FakePath:
def __init__(self, _):
pass
def resolve(self):
raise OSError

Path = plugin.Path
plugin.Path = FakePath
plugin.MypyResults.from_mypy([], opts=['--version'])
plugin.Path = Path
""",
)
result = testdir.runpytest_subprocess("--mypy", *xdist_args)
mypy_file_checks = 1
mypy_status_check = 1
mypy_checks = mypy_file_checks + mypy_status_check
result.assert_outcomes(passed=mypy_checks)
assert result.ret == pytest.ExitCode.OK


def test_mypy_annotation_unchecked(testdir, xdist_args, tmp_path):
"""Verify that annotation-unchecked warnings do not manifest as an error."""
testdir.makepyfile(
"""
Expand Down