12
12
from typing import Dict
13
13
from typing import final
14
14
from typing import FrozenSet
15
- from typing import Generator
16
15
from typing import Iterable
17
16
from typing import Iterator
18
17
from typing import List
@@ -501,11 +500,11 @@ def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
501
500
config = self .config
502
501
col : Optional [nodes .Collector ]
503
502
cols : Sequence [nodes .Collector ]
503
+ ihook = self .ihook
504
504
for direntry in scandir (self .path ):
505
505
if direntry .is_dir ():
506
506
if direntry .name == "__pycache__" :
507
507
continue
508
- ihook = self .ihook
509
508
path = Path (direntry .path )
510
509
if not self .session .isinitpath (path , with_parents = True ):
511
510
if ihook .pytest_ignore_collect (collection_path = path , config = config ):
@@ -515,7 +514,6 @@ def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
515
514
yield col
516
515
517
516
elif direntry .is_file ():
518
- ihook = self .ihook
519
517
path = Path (direntry .path )
520
518
if not self .session .isinitpath (path ):
521
519
if ihook .pytest_ignore_collect (collection_path = path , config = config ):
@@ -558,7 +556,6 @@ def __init__(self, config: Config) -> None:
558
556
self ._initialpaths_with_parents : FrozenSet [Path ] = frozenset ()
559
557
self ._notfound : List [Tuple [str , Sequence [nodes .Collector ]]] = []
560
558
self ._initial_parts : List [Tuple [Path , List [str ]]] = []
561
- self ._in_genitems = False
562
559
self ._collection_cache : Dict [nodes .Collector , CollectReport ] = {}
563
560
self .items : List [nodes .Item ] = []
564
561
@@ -611,29 +608,6 @@ def pytest_runtest_logreport(
611
608
612
609
pytest_collectreport = pytest_runtest_logreport
613
610
614
- @hookimpl (wrapper = True )
615
- def pytest_collect_directory (
616
- self ,
617
- ) -> Generator [None , Optional [nodes .Collector ], Optional [nodes .Collector ]]:
618
- col = yield
619
-
620
- # Eagerly load conftests for the directory.
621
- # This is needed because a conftest error needs to happen while
622
- # collecting a collector, so it is caught by its CollectReport.
623
- # Without this, the conftests are loaded inside of genitems itself
624
- # which leads to an internal error.
625
- # This should only be done for genitems; if done unconditionally, it
626
- # will load conftests for non-selected directories which is to be
627
- # avoided.
628
- if self ._in_genitems and col is not None :
629
- self .config .pluginmanager ._loadconftestmodules (
630
- col .path ,
631
- self .config .getoption ("importmode" ),
632
- rootpath = self .config .rootpath ,
633
- )
634
-
635
- return col
636
-
637
611
def isinitpath (
638
612
self ,
639
613
path : Union [str , "os.PathLike[str]" ],
@@ -664,15 +638,6 @@ def gethookproxy(self, fspath: "os.PathLike[str]") -> pluggy.HookRelay:
664
638
pm = self .config .pluginmanager
665
639
# Check if we have the common case of running
666
640
# hooks with all conftest.py files.
667
- #
668
- # TODO: pytest relies on this call to load non-initial conftests. This
669
- # is incidental. It will be better to load conftests at a more
670
- # well-defined place.
671
- pm ._loadconftestmodules (
672
- path ,
673
- self .config .getoption ("importmode" ),
674
- rootpath = self .config .rootpath ,
675
- )
676
641
my_conftestmodules = pm ._getconftestmodules (path )
677
642
remove_mods = pm ._conftest_plugins .difference (my_conftestmodules )
678
643
proxy : pluggy .HookRelay
@@ -753,7 +718,6 @@ def perform_collect( # noqa: F811
753
718
754
719
self ._notfound = []
755
720
self ._initial_parts = []
756
- self ._in_genitems = False
757
721
self ._collection_cache = {}
758
722
self .items = []
759
723
items : Sequence [Union [nodes .Item , nodes .Collector ]] = self .items
@@ -788,7 +752,6 @@ def perform_collect( # noqa: F811
788
752
789
753
raise UsageError (* errors )
790
754
791
- self ._in_genitems = True
792
755
if not genitems :
793
756
items = rep .result
794
757
else :
@@ -803,7 +766,6 @@ def perform_collect( # noqa: F811
803
766
finally :
804
767
self ._notfound = []
805
768
self ._initial_parts = []
806
- self ._in_genitems = False
807
769
self ._collection_cache = {}
808
770
hook .pytest_collection_finish (session = self )
809
771
0 commit comments