33
33
from _pytest .main import ExitCode
34
34
from _pytest .main import Session
35
35
from _pytest .monkeypatch import MonkeyPatch
36
+ from _pytest .nodes import Collector
37
+ from _pytest .nodes import Item
36
38
from _pytest .pathlib import Path
39
+ from _pytest .python import Module
37
40
from _pytest .reports import TestReport
38
41
from _pytest .tmpdir import TempdirFactory
39
42
@@ -537,7 +540,9 @@ class TimeoutExpired(Exception):
537
540
538
541
def __init__ (self , request : FixtureRequest , tmpdir_factory : TempdirFactory ) -> None :
539
542
self .request = request
540
- self ._mod_collections = WeakKeyDictionary () # type: ignore[var-annotated] # noqa: F821
543
+ self ._mod_collections = (
544
+ WeakKeyDictionary ()
545
+ ) # type: WeakKeyDictionary[Module, List[Union[Item, Collector]]]
541
546
name = request .function .__name__
542
547
self .tmpdir = tmpdir_factory .mktemp (name , numbered = True )
543
548
self .test_tmproot = tmpdir_factory .mktemp ("tmp-" + name , numbered = True )
@@ -1065,7 +1070,9 @@ def getmodulecol(self, source, configargs=(), withinit=False):
1065
1070
self .config = config = self .parseconfigure (path , * configargs )
1066
1071
return self .getnode (config , path )
1067
1072
1068
- def collect_by_name (self , modcol , name ):
1073
+ def collect_by_name (
1074
+ self , modcol : Module , name : str
1075
+ ) -> Optional [Union [Item , Collector ]]:
1069
1076
"""Return the collection node for name from the module collection.
1070
1077
1071
1078
This will search a module collection node for a collection node
@@ -1081,6 +1088,7 @@ def collect_by_name(self, modcol, name):
1081
1088
for colitem in self ._mod_collections [modcol ]:
1082
1089
if colitem .name == name :
1083
1090
return colitem
1091
+ return None
1084
1092
1085
1093
def popen (
1086
1094
self ,
0 commit comments