1
1
"""Mypy static type checker plugin for Pytest"""
2
2
3
+ import os
4
+
3
5
import pytest
4
6
import mypy .api
5
7
@@ -46,7 +48,7 @@ def pytest_collect_file(path, parent):
46
48
def pytest_runtestloop (session ):
47
49
"""Run mypy on collected MypyItems, then sort the output."""
48
50
mypy_items = {
49
- item . mypy_path ( ): item
51
+ os . path . abspath ( str ( item . fspath ) ): item
50
52
for item in session .items
51
53
if isinstance (item , MypyItem )
52
54
}
@@ -70,7 +72,7 @@ def pytest_runtestloop(session):
70
72
continue
71
73
mypy_path , _ , error = line .partition (':' )
72
74
try :
73
- item = mypy_items [mypy_path ]
75
+ item = mypy_items [os . path . abspath ( mypy_path ) ]
74
76
except KeyError :
75
77
unmatched_lines .append (line )
76
78
else :
@@ -94,19 +96,19 @@ def __init__(self, *args, **kwargs):
94
96
self .add_marker (self .MARKER )
95
97
self .mypy_errors = []
96
98
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
-
105
99
def runtest (self ):
106
100
"""Raise an exception if mypy found errors for this item."""
107
101
if self .mypy_errors :
108
102
raise MypyError ('\n ' .join (self .mypy_errors ))
109
103
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
+
110
112
def repr_failure (self , excinfo ):
111
113
"""
112
114
Unwrap mypy errors so we get a clean error message without the
0 commit comments