@@ -48,7 +48,7 @@ def pytest_collect_file(path, parent):
48
48
def pytest_runtestloop (session ):
49
49
"""Run mypy on collected MypyItems, then sort the output."""
50
50
mypy_items = {
51
- item . mypy_path ( ): item
51
+ os . path . abspath ( str ( item . fspath ) ): item
52
52
for item in session .items
53
53
if isinstance (item , MypyItem )
54
54
}
@@ -72,7 +72,7 @@ def pytest_runtestloop(session):
72
72
continue
73
73
mypy_path , _ , error = line .partition (':' )
74
74
try :
75
- item = mypy_items [mypy_path ]
75
+ item = mypy_items [os . path . abspath ( mypy_path ) ]
76
76
except KeyError :
77
77
unmatched_lines .append (line )
78
78
else :
@@ -85,18 +85,6 @@ def pytest_runtestloop(session):
85
85
terminal .write_line (stderr , red = True )
86
86
87
87
88
- # mypy.errors.remove_path_prefix is not public.
89
- # https://github.com/python/mypy/blob/fdcbb74b2e01f6afd0549da6375a66aab839fd9a/mypy/errors.py#L647-L654
90
- def _remove_path_prefix (path , prefix ):
91
- """If path starts with prefix, return copy of path with the prefix removed.
92
- Otherwise, return path. If path is None, return None.
93
- """
94
- if prefix is not None and path .startswith (prefix ):
95
- return path [len (prefix ):]
96
- else :
97
- return path
98
-
99
-
100
88
class MypyItem (pytest .Item , pytest .File ):
101
89
102
90
"""A File that Mypy Runs On."""
@@ -108,34 +96,19 @@ def __init__(self, *args, **kwargs):
108
96
self .add_marker (self .MARKER )
109
97
self .mypy_errors = []
110
98
111
- def mypy_path (self ):
112
- """Get the path that is expected to show up in Mypy results."""
113
- # Mypy does not currently expose this computation, so...
114
- # https://github.com/python/mypy/blob/fdcbb74b2e01f6afd0549da6375a66aab839fd9a/mypy/build.py#L214
115
- prefix = ignore_prefix = os .getcwd ()
116
- # https://github.com/python/mypy/blob/fdcbb74b2e01f6afd0549da6375a66aab839fd9a/mypy/errors.py#L208-L214
117
- prefix = os .path .normpath (prefix )
118
- # Add separator to the end, if not given.
119
- if os .path .basename (prefix ) != '' :
120
- prefix += os .sep
121
- ignore_prefix = prefix
122
- # https://github.com/python/mypy/blob/fdcbb74b2e01f6afd0549da6375a66aab839fd9a/mypy/errors.py#L535
123
- # https://github.com/python/mypy/blob/fdcbb74b2e01f6afd0549da6375a66aab839fd9a/mypy/errors.py#L216-L221
124
- if '--show-absolute-path' in mypy_argv :
125
- return os .path .abspath (str (self .fspath ))
126
- else :
127
- path = os .path .normpath (str (self .fspath ))
128
- return _remove_path_prefix (path , ignore_prefix )
129
-
130
- def reportinfo (self ):
131
- """Produce a heading for the test report."""
132
- return self .fspath , None , self .mypy_path ()
133
-
134
99
def runtest (self ):
135
100
"""Raise an exception if mypy found errors for this item."""
136
101
if self .mypy_errors :
137
102
raise MypyError ('\n ' .join (self .mypy_errors ))
138
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
+
139
112
def repr_failure (self , excinfo ):
140
113
"""
141
114
Unwrap mypy errors so we get a clean error message without the
0 commit comments