Skip to content

Commit ab7505e

Browse files
authored
Merge pull request #59 from dmtucker/paths
Remove MypyItem.mypy_path
2 parents 35b5986 + 5aecc10 commit ab7505e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/pytest_mypy.py

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

3+
import os
4+
35
import pytest
46
import mypy.api
57

@@ -46,7 +48,7 @@ def pytest_collect_file(path, parent):
4648
def pytest_runtestloop(session):
4749
"""Run mypy on collected MypyItems, then sort the output."""
4850
mypy_items = {
49-
item.mypy_path(): item
51+
os.path.abspath(str(item.fspath)): item
5052
for item in session.items
5153
if isinstance(item, MypyItem)
5254
}
@@ -70,7 +72,7 @@ def pytest_runtestloop(session):
7072
continue
7173
mypy_path, _, error = line.partition(':')
7274
try:
73-
item = mypy_items[mypy_path]
75+
item = mypy_items[os.path.abspath(mypy_path)]
7476
except KeyError:
7577
unmatched_lines.append(line)
7678
else:
@@ -94,19 +96,19 @@ def __init__(self, *args, **kwargs):
9496
self.add_marker(self.MARKER)
9597
self.mypy_errors = []
9698

97-
def mypy_path(self):
98-
"""Get the path that is expected to show up in Mypy results."""
99-
return self.fspath.relto(self.config.rootdir)
100-
101-
def reportinfo(self):
102-
"""Produce a heading for the test report."""
103-
return self.fspath, None, self.mypy_path()
104-
10599
def runtest(self):
106100
"""Raise an exception if mypy found errors for this item."""
107101
if self.mypy_errors:
108102
raise MypyError('\n'.join(self.mypy_errors))
109103

104+
def reportinfo(self):
105+
"""Produce a heading for the test report."""
106+
return (
107+
self.fspath,
108+
None,
109+
self.config.invocation_dir.bestrelpath(self.fspath),
110+
)
111+
110112
def repr_failure(self, excinfo):
111113
"""
112114
Unwrap mypy errors so we get a clean error message without the

0 commit comments

Comments
 (0)