45
45
from typing import Type
46
46
from typing_extensions import Literal
47
47
48
- from _pytest .python import Package
49
-
50
48
51
49
def pytest_addoption (parser : Parser ) -> None :
52
50
parser .addini (
@@ -443,23 +441,6 @@ def __init__(self, config: Config) -> None:
443
441
self .startdir = config .invocation_dir
444
442
self ._initialpaths = frozenset () # type: FrozenSet[py.path.local]
445
443
446
- # Keep track of any collected nodes in here, so we don't duplicate fixtures.
447
- self ._collection_node_cache1 = (
448
- {}
449
- ) # type: Dict[py.path.local, Sequence[nodes.Collector]]
450
- self ._collection_node_cache2 = (
451
- {}
452
- ) # type: Dict[Tuple[Type[nodes.Collector], py.path.local], nodes.Collector]
453
-
454
- # Keep track of any collected collectors in matchnodes paths, so they
455
- # are not collected more than once.
456
- self ._collection_matchnodes_cache = (
457
- {}
458
- ) # type: Dict[Tuple[Type[nodes.Collector], str], CollectReport]
459
-
460
- # Dirnames of pkgs with dunder-init files.
461
- self ._collection_pkg_roots = {} # type: Dict[str, Package]
462
-
463
444
self ._bestrelpathcache = _bestrelpath_cache (
464
445
config .rootdir
465
446
) # type: Dict[py.path.local, str]
@@ -639,6 +620,21 @@ def perform_collect( # noqa: F811
639
620
def collect (self ) -> Iterator [Union [nodes .Item , nodes .Collector ]]:
640
621
from _pytest .python import Package
641
622
623
+ # Keep track of any collected nodes in here, so we don't duplicate fixtures.
624
+ node_cache1 = {} # type: Dict[py.path.local, Sequence[nodes.Collector]]
625
+ node_cache2 = (
626
+ {}
627
+ ) # type: Dict[Tuple[Type[nodes.Collector], py.path.local], nodes.Collector]
628
+
629
+ # Keep track of any collected collectors in matchnodes paths, so they
630
+ # are not collected more than once.
631
+ matchnodes_cache = (
632
+ {}
633
+ ) # type: Dict[Tuple[Type[nodes.Collector], str], CollectReport]
634
+
635
+ # Dirnames of pkgs with dunder-init files.
636
+ pkg_roots = {} # type: Dict[str, Package]
637
+
642
638
for argpath , names in self ._initial_parts :
643
639
self .trace ("processing argument" , (argpath , names ))
644
640
self .trace .root .indent += 1
@@ -655,14 +651,12 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
655
651
if parent .isdir ():
656
652
pkginit = parent .join ("__init__.py" )
657
653
if pkginit .isfile ():
658
- if pkginit not in self . _collection_node_cache1 :
654
+ if pkginit not in node_cache1 :
659
655
col = self ._collectfile (pkginit , handle_dupes = False )
660
656
if col :
661
657
if isinstance (col [0 ], Package ):
662
- self ._collection_pkg_roots [str (parent )] = col [0 ]
663
- self ._collection_node_cache1 [col [0 ].fspath ] = [
664
- col [0 ]
665
- ]
658
+ pkg_roots [str (parent )] = col [0 ]
659
+ node_cache1 [col [0 ].fspath ] = [col [0 ]]
666
660
667
661
# If it's a directory argument, recurse and look for any Subpackages.
668
662
# Let the Package collector deal with subnodes, don't collect here.
@@ -685,28 +679,28 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
685
679
for x in self ._collectfile (pkginit ):
686
680
yield x
687
681
if isinstance (x , Package ):
688
- self . _collection_pkg_roots [str (dirpath )] = x
689
- if str (dirpath ) in self . _collection_pkg_roots :
682
+ pkg_roots [str (dirpath )] = x
683
+ if str (dirpath ) in pkg_roots :
690
684
# Do not collect packages here.
691
685
continue
692
686
693
687
for x in self ._collectfile (path ):
694
688
key = (type (x ), x .fspath )
695
- if key in self . _collection_node_cache2 :
696
- yield self . _collection_node_cache2 [key ]
689
+ if key in node_cache2 :
690
+ yield node_cache2 [key ]
697
691
else :
698
- self . _collection_node_cache2 [key ] = x
692
+ node_cache2 [key ] = x
699
693
yield x
700
694
else :
701
695
assert argpath .check (file = 1 )
702
696
703
- if argpath in self . _collection_node_cache1 :
704
- col = self . _collection_node_cache1 [argpath ]
697
+ if argpath in node_cache1 :
698
+ col = node_cache1 [argpath ]
705
699
else :
706
- collect_root = self . _collection_pkg_roots .get (argpath .dirname , self )
700
+ collect_root = pkg_roots .get (argpath .dirname , self )
707
701
col = collect_root ._collectfile (argpath , handle_dupes = False )
708
702
if col :
709
- self . _collection_node_cache1 [argpath ] = col
703
+ node_cache1 [argpath ] = col
710
704
711
705
matching = []
712
706
work = [
@@ -724,11 +718,11 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
724
718
if not isinstance (node , nodes .Collector ):
725
719
continue
726
720
key = (type (node ), node .nodeid )
727
- if key in self . _collection_matchnodes_cache :
728
- rep = self . _collection_matchnodes_cache [key ]
721
+ if key in matchnodes_cache :
722
+ rep = matchnodes_cache [key ]
729
723
else :
730
724
rep = collect_one_node (node )
731
- self . _collection_matchnodes_cache [key ] = rep
725
+ matchnodes_cache [key ] = rep
732
726
if rep .passed :
733
727
submatchnodes = []
734
728
for r in rep .result :
@@ -776,10 +770,6 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
776
770
yield from matching
777
771
778
772
self .trace .root .indent -= 1
779
- self ._collection_node_cache1 .clear ()
780
- self ._collection_node_cache2 .clear ()
781
- self ._collection_matchnodes_cache .clear ()
782
- self ._collection_pkg_roots .clear ()
783
773
784
774
def genitems (
785
775
self , node : Union [nodes .Item , nodes .Collector ]
0 commit comments