11"""Mypy static type checker plugin for Pytest"""
22
3+ import os
4+
35import pytest
46import mypy .api
57
@@ -46,7 +48,7 @@ def pytest_collect_file(path, parent):
4648def 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