3333from _pytest .main import ExitCode
3434from _pytest .main import Session
3535from _pytest .monkeypatch import MonkeyPatch
36+ from _pytest .nodes import Collector
37+ from _pytest .nodes import Item
3638from _pytest .pathlib import Path
39+ from _pytest .python import Module
3740from _pytest .reports import TestReport
3841from _pytest .tmpdir import TempdirFactory
3942
@@ -537,7 +540,9 @@ class TimeoutExpired(Exception):
537540
538541 def __init__ (self , request : FixtureRequest , tmpdir_factory : TempdirFactory ) -> None :
539542 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]]]
541546 name = request .function .__name__
542547 self .tmpdir = tmpdir_factory .mktemp (name , numbered = True )
543548 self .test_tmproot = tmpdir_factory .mktemp ("tmp-" + name , numbered = True )
@@ -1065,7 +1070,9 @@ def getmodulecol(self, source, configargs=(), withinit=False):
10651070 self .config = config = self .parseconfigure (path , * configargs )
10661071 return self .getnode (config , path )
10671072
1068- def collect_by_name (self , modcol , name ):
1073+ def collect_by_name (
1074+ self , modcol : Module , name : str
1075+ ) -> Optional [Union [Item , Collector ]]:
10691076 """Return the collection node for name from the module collection.
10701077
10711078 This will search a module collection node for a collection node
@@ -1081,6 +1088,7 @@ def collect_by_name(self, modcol, name):
10811088 for colitem in self ._mod_collections [modcol ]:
10821089 if colitem .name == name :
10831090 return colitem
1091+ return None
10841092
10851093 def popen (
10861094 self ,
0 commit comments