@@ -48,7 +48,7 @@ def pytest_collect_file(path, parent):
4848def pytest_runtestloop (session ):
4949 """Run mypy on collected MypyItems, then sort the output."""
5050 mypy_items = {
51- item . mypy_path ( ): item
51+ os . path . abspath ( str ( item . fspath ) ): item
5252 for item in session .items
5353 if isinstance (item , MypyItem )
5454 }
@@ -72,7 +72,7 @@ def pytest_runtestloop(session):
7272 continue
7373 mypy_path , _ , error = line .partition (':' )
7474 try :
75- item = mypy_items [mypy_path ]
75+ item = mypy_items [os . path . abspath ( mypy_path ) ]
7676 except KeyError :
7777 unmatched_lines .append (line )
7878 else :
@@ -85,18 +85,6 @@ def pytest_runtestloop(session):
8585 terminal .write_line (stderr , red = True )
8686
8787
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-
10088class MypyItem (pytest .Item , pytest .File ):
10189
10290 """A File that Mypy Runs On."""
@@ -108,34 +96,19 @@ def __init__(self, *args, **kwargs):
10896 self .add_marker (self .MARKER )
10997 self .mypy_errors = []
11098
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-
13499 def runtest (self ):
135100 """Raise an exception if mypy found errors for this item."""
136101 if self .mypy_errors :
137102 raise MypyError ('\n ' .join (self .mypy_errors ))
138103
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+
139112 def repr_failure (self , excinfo ):
140113 """
141114 Unwrap mypy errors so we get a clean error message without the
0 commit comments