@@ -43,10 +43,11 @@ def __init__(
4343 * ,
4444 mypy_item : MypyTestItem ,
4545 config : Optional [Config ] = None ,
46+ ** kwargs ,
4647 ) -> None :
4748 if config is None :
4849 config = parent .config
49- super ().__init__ (name , parent = parent , config = config )
50+ super ().__init__ (name , parent = parent , config = config , ** kwargs )
5051 self .add_marker ("mypy" )
5152 self .mypy_item = mypy_item
5253 for mark in self .mypy_item .marks :
@@ -103,22 +104,37 @@ def repr_failure(self, excinfo, style=None):
103104
104105class PytestMypyFile (pytest .File ):
105106 def __init__ (
106- self , fspath : LocalPath , parent = None , config = None , session = None , nodeid = None
107+ self ,
108+ * ,
109+ parent = None ,
110+ config = None ,
111+ session = None ,
112+ nodeid = None ,
113+ ** kwargs ,
107114 ) -> None :
108115 if config is None :
109116 config = getattr (parent , "config" , None )
110- super ().__init__ (fspath , parent , config , session , nodeid )
117+ super ().__init__ (
118+ parent = parent ,
119+ config = config ,
120+ session = session ,
121+ nodeid = nodeid ,
122+ ** kwargs ,
123+ )
111124 self .add_marker ("mypy" )
112- self .mypy_file = parse_file (self .fspath , config = config )
125+ if PYTEST_VERSION_INFO >= (7 ,):
126+ self .mypy_file = parse_file (self .path , config = config )
127+ else :
128+ self .mypy_file = parse_file (self .fspath , config = config )
113129 self ._mypy_result : Optional [MypyResult ] = None
114130
115131 @classmethod
116- def from_parent (cls , parent , fspath ):
132+ def from_parent (cls , parent , ** kwargs ):
117133 if PYTEST_VERSION_INFO < (5 , 4 ):
118134 config = getattr (parent , "config" , None )
119- return cls (parent = parent , config = config , fspath = fspath )
135+ return cls (parent = parent , config = config , ** kwargs )
120136 else :
121- return super ().from_parent (parent = parent , fspath = fspath )
137+ return super ().from_parent (parent = parent , ** kwargs )
122138
123139 def collect (self ) -> Iterator [PytestMypyTestItem ]:
124140 for item in self .mypy_file .items :
@@ -195,12 +211,23 @@ def _run_mypy(self, filename: str) -> MypyResult:
195211 )
196212
197213
198- def pytest_collect_file (path : LocalPath , parent ):
199- if path .ext == ".mypy-testing" or _is_pytest_test_file (path , parent ):
200- file = PytestMypyFile .from_parent (parent = parent , fspath = path )
201- if file .mypy_file .items :
202- return file
203- return None
214+ if PYTEST_VERSION_INFO < (7 ,):
215+
216+ def pytest_collect_file (path : LocalPath , parent ):
217+ if path .ext == ".mypy-testing" or _is_pytest_test_file (path , parent ):
218+ file = PytestMypyFile .from_parent (parent = parent , fspath = path )
219+ if file .mypy_file .items :
220+ return file
221+ return None
222+
223+ else :
224+
225+ def pytest_collect_file (file_path , path : LocalPath , parent ): # type: ignore
226+ if path .ext == ".mypy-testing" or _is_pytest_test_file (path , parent ):
227+ file = PytestMypyFile .from_parent (parent = parent , path = file_path )
228+ if file .mypy_file .items :
229+ return file
230+ return None
204231
205232
206233def _is_pytest_test_file (path : LocalPath , parent ):
0 commit comments