2929from _pytest .capture import MultiCapture
3030from _pytest .capture import SysCapture
3131from _pytest .compat import TYPE_CHECKING
32+ from _pytest .config import _PluggyPlugin
3233from _pytest .fixtures import FixtureRequest
3334from _pytest .main import ExitCode
3435from _pytest .main import Session
3536from _pytest .monkeypatch import MonkeyPatch
37+ from _pytest .nodes import Collector
38+ from _pytest .nodes import Item
3639from _pytest .pathlib import Path
40+ from _pytest .python import Module
3741from _pytest .reports import TestReport
42+ from _pytest .tmpdir import TempdirFactory
3843
3944if TYPE_CHECKING :
4045 from typing import Type
@@ -534,13 +539,15 @@ class Testdir:
534539 class TimeoutExpired (Exception ):
535540 pass
536541
537- def __init__ (self , request , tmpdir_factory ) :
542+ def __init__ (self , request : FixtureRequest , tmpdir_factory : TempdirFactory ) -> None :
538543 self .request = request
539- self ._mod_collections = WeakKeyDictionary ()
544+ self ._mod_collections = (
545+ WeakKeyDictionary ()
546+ ) # type: WeakKeyDictionary[Module, List[Union[Item, Collector]]]
540547 name = request .function .__name__
541548 self .tmpdir = tmpdir_factory .mktemp (name , numbered = True )
542549 self .test_tmproot = tmpdir_factory .mktemp ("tmp-" + name , numbered = True )
543- self .plugins = []
550+ self .plugins = [] # type: List[Union[str, _PluggyPlugin]]
544551 self ._cwd_snapshot = CwdSnapshot ()
545552 self ._sys_path_snapshot = SysPathsSnapshot ()
546553 self ._sys_modules_snapshot = self .__take_sys_modules_snapshot ()
@@ -1064,7 +1071,9 @@ def getmodulecol(self, source, configargs=(), withinit=False):
10641071 self .config = config = self .parseconfigure (path , * configargs )
10651072 return self .getnode (config , path )
10661073
1067- def collect_by_name (self , modcol , name ):
1074+ def collect_by_name (
1075+ self , modcol : Module , name : str
1076+ ) -> Optional [Union [Item , Collector ]]:
10681077 """Return the collection node for name from the module collection.
10691078
10701079 This will search a module collection node for a collection node
@@ -1073,13 +1082,13 @@ def collect_by_name(self, modcol, name):
10731082 :param modcol: a module collection node; see :py:meth:`getmodulecol`
10741083
10751084 :param name: the name of the node to return
1076-
10771085 """
10781086 if modcol not in self ._mod_collections :
10791087 self ._mod_collections [modcol ] = list (modcol .collect ())
10801088 for colitem in self ._mod_collections [modcol ]:
10811089 if colitem .name == name :
10821090 return colitem
1091+ return None
10831092
10841093 def popen (
10851094 self ,
0 commit comments