Skip to content
Merged
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
22 changes: 12 additions & 10 deletions src/pytest_mypy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Mypy static type checker plugin for Pytest"""

import os

import pytest
import mypy.api

Expand Down Expand Up @@ -46,7 +48,7 @@ def pytest_collect_file(path, parent):
def pytest_runtestloop(session):
"""Run mypy on collected MypyItems, then sort the output."""
mypy_items = {
item.mypy_path(): item
os.path.abspath(str(item.fspath)): item
for item in session.items
if isinstance(item, MypyItem)
}
Expand All @@ -70,7 +72,7 @@ def pytest_runtestloop(session):
continue
mypy_path, _, error = line.partition(':')
try:
item = mypy_items[mypy_path]
item = mypy_items[os.path.abspath(mypy_path)]
except KeyError:
unmatched_lines.append(line)
else:
Expand All @@ -94,19 +96,19 @@ def __init__(self, *args, **kwargs):
self.add_marker(self.MARKER)
self.mypy_errors = []

def mypy_path(self):
"""Get the path that is expected to show up in Mypy results."""
return self.fspath.relto(self.config.rootdir)

def reportinfo(self):
"""Produce a heading for the test report."""
return self.fspath, None, self.mypy_path()

def runtest(self):
"""Raise an exception if mypy found errors for this item."""
if self.mypy_errors:
raise MypyError('\n'.join(self.mypy_errors))

def reportinfo(self):
"""Produce a heading for the test report."""
return (
self.fspath,
None,
self.config.invocation_dir.bestrelpath(self.fspath),
)

def repr_failure(self, excinfo):
"""
Unwrap mypy errors so we get a clean error message without the
Expand Down