99from abc import abstractmethod
1010import sys
1111
12- import pytest # type: ignore # no pytest in typeshed
12+ import pytest
1313from typing import List , Tuple , Set , Optional , Iterator , Any , Dict , NamedTuple , Union
1414
1515from mypy .test .config import test_data_prefix , test_temp_dir , PREFIX
@@ -160,9 +160,12 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
160160 case .expected_fine_grained_targets = targets
161161
162162
163- class DataDrivenTestCase (pytest .Item ): # type: ignore # inheriting from Any
163+ class DataDrivenTestCase (pytest .Item ):
164164 """Holds parsed data-driven test cases, and handles directory setup and teardown."""
165165
166+ # Override parent member type
167+ parent = None # type: DataSuiteCollector
168+
166169 input = None # type: List[str]
167170 output = None # type: List[str] # Output for the first pass
168171 output2 = None # type: Dict[int, List[str]] # Output for runs 2+, indexed by run number
@@ -266,7 +269,7 @@ def repr_failure(self, excinfo: Any, style: Optional[Any] = None) -> str:
266269 # call exit() and they already print out a stack trace.
267270 excrepr = excinfo .exconly ()
268271 else :
269- self .parent ._prunetraceback (excinfo )
272+ self .parent ._prunetraceback (excinfo ) # type: ignore[no-untyped-call]
270273 excrepr = excinfo .getrepr (style = 'short' )
271274
272275 return "data: {}:{}:\n {}" .format (self .file , self .line , excrepr )
@@ -510,7 +513,9 @@ def pytest_pycollect_makeitem(collector: Any, name: str,
510513 # Non-None result means this obj is a test case.
511514 # The collect method of the returned DataSuiteCollector instance will be called later,
512515 # with self.obj being obj.
513- return DataSuiteCollector (name , parent = collector )
516+ return DataSuiteCollector .from_parent ( # type: ignore[no-untyped-call]
517+ parent = collector , name = name
518+ )
514519 return None
515520
516521
@@ -535,19 +540,23 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite',
535540 for i in range (1 , len (cases ), 6 ):
536541 name , writescache , only_when , platform_flag , skip , data = cases [i :i + 6 ]
537542 platform = platform_flag [1 :] if platform_flag else None
538- yield DataDrivenTestCase (parent , suite , file ,
539- name = add_test_name_suffix (name , suite .test_name_suffix ),
540- writescache = bool (writescache ),
541- only_when = only_when ,
542- platform = platform ,
543- skip = bool (skip ),
544- data = data ,
545- line = line_no )
543+ yield DataDrivenTestCase .from_parent (
544+ parent = parent ,
545+ suite = suite ,
546+ file = file ,
547+ name = add_test_name_suffix (name , suite .test_name_suffix ),
548+ writescache = bool (writescache ),
549+ only_when = only_when ,
550+ platform = platform ,
551+ skip = bool (skip ),
552+ data = data ,
553+ line = line_no ,
554+ )
546555 line_no += data .count ('\n ' ) + 1
547556
548557
549- class DataSuiteCollector (pytest .Class ): # type: ignore # inheriting from Any
550- def collect (self ) -> Iterator [pytest .Item ]: # type: ignore
558+ class DataSuiteCollector (pytest .Class ):
559+ def collect (self ) -> Iterator [pytest .Item ]:
551560 """Called by pytest on each of the object returned from pytest_pycollect_makeitem"""
552561
553562 # obj is the object for which pytest_pycollect_makeitem returned self.
0 commit comments