@@ -73,14 +73,14 @@ def pytest_configure_node(self, node): # xdist hook
7373
7474
7575def pytest_collect_file (path , parent ):
76- """Create a MypyItem for every file mypy should run on."""
76+ """Create a MypyFileItem for every file mypy should run on."""
7777 if path .ext == '.py' and any ([
7878 parent .config .option .mypy ,
7979 parent .config .option .mypy_ignore_missing_imports ,
8080 ]):
81- item = MypyItem (path , parent )
81+ item = MypyFileItem (path , parent )
8282 if nodeid_name :
83- item = MypyItem (
83+ item = MypyFileItem (
8484 path ,
8585 parent ,
8686 nodeid = '::' .join ([item .nodeid , nodeid_name ]),
@@ -89,16 +89,30 @@ def pytest_collect_file(path, parent):
8989 return None
9090
9191
92- class MypyItem (pytest .Item , pytest . File ):
92+ class MypyItem (pytest .Item ):
9393
94- """A File that Mypy Runs On ."""
94+ """A Mypy-related test Item ."""
9595
9696 MARKER = 'mypy'
9797
9898 def __init__ (self , * args , ** kwargs ):
9999 super ().__init__ (* args , ** kwargs )
100100 self .add_marker (self .MARKER )
101101
102+ def repr_failure (self , excinfo ):
103+ """
104+ Unwrap mypy errors so we get a clean error message without the
105+ full exception repr.
106+ """
107+ if excinfo .errisinstance (MypyError ):
108+ return excinfo .value .args [0 ]
109+ return super ().repr_failure (excinfo )
110+
111+
112+ class MypyFileItem (MypyItem , pytest .File ):
113+
114+ """A File that Mypy Runs On."""
115+
102116 def runtest (self ):
103117 """Raise an exception if mypy found errors for this item."""
104118 results = _cached_json_results (
@@ -112,7 +126,7 @@ def runtest(self):
112126 abspaths = [
113127 os .path .abspath (str (item .fspath ))
114128 for item in self .session .items
115- if isinstance (item , MypyItem )
129+ if isinstance (item , MypyFileItem )
116130 ],
117131 )
118132 )
@@ -129,15 +143,6 @@ def reportinfo(self):
129143 self .config .invocation_dir .bestrelpath (self .fspath ),
130144 )
131145
132- def repr_failure (self , excinfo ):
133- """
134- Unwrap mypy errors so we get a clean error message without the
135- full exception repr.
136- """
137- if excinfo .errisinstance (MypyError ):
138- return excinfo .value .args [0 ]
139- return super ().repr_failure (excinfo )
140-
141146
142147def _cached_json_results (results_path , results_factory = None ):
143148 """
0 commit comments