8
8
from typing import Dict
9
9
from typing import FrozenSet
10
10
from typing import List
11
+ from typing import Sequence
11
12
from typing import Tuple
12
13
13
14
import attr
21
22
from _pytest .config import hookimpl
22
23
from _pytest .config import UsageError
23
24
from _pytest .fixtures import FixtureManager
24
- from _pytest .nodes import Node
25
25
from _pytest .outcomes import exit
26
+ from _pytest .reports import CollectReport
26
27
from _pytest .runner import collect_one_node
27
28
from _pytest .runner import SetupState
28
29
29
30
30
31
if TYPE_CHECKING :
32
+ from typing import Type
33
+
31
34
from _pytest .python import Package
32
35
33
36
@@ -407,7 +410,16 @@ def __init__(self, config: Config) -> None:
407
410
self ._initialpaths = frozenset () # type: FrozenSet[py.path.local]
408
411
409
412
# Keep track of any collected nodes in here, so we don't duplicate fixtures
410
- self ._collection_node_cache = {} # type: Dict[str, List[Node]]
413
+ self ._collection_node_cache1 = (
414
+ {}
415
+ ) # type: Dict[py.path.local, Sequence[nodes.Collector]]
416
+ self ._collection_node_cache2 = (
417
+ {}
418
+ ) # type: Dict[Tuple[Type[nodes.Collector], py.path.local], nodes.Collector]
419
+ self ._collection_node_cache3 = (
420
+ {}
421
+ ) # type: Dict[Tuple[Type[nodes.Collector], str], CollectReport]
422
+
411
423
# Dirnames of pkgs with dunder-init files.
412
424
self ._collection_pkg_roots = {} # type: Dict[py.path.local, Package]
413
425
@@ -525,7 +537,9 @@ def collect(self):
525
537
self ._notfound .append ((report_arg , sys .exc_info ()[1 ]))
526
538
527
539
self .trace .root .indent -= 1
528
- self ._collection_node_cache .clear ()
540
+ self ._collection_node_cache1 .clear ()
541
+ self ._collection_node_cache2 .clear ()
542
+ self ._collection_node_cache3 .clear ()
529
543
self ._collection_pkg_roots .clear ()
530
544
531
545
def _collect (self , argpath , names ):
@@ -543,13 +557,13 @@ def _collect(self, argpath, names):
543
557
if parent .isdir ():
544
558
pkginit = parent .join ("__init__.py" )
545
559
if pkginit .isfile ():
546
- if pkginit not in self ._collection_node_cache :
560
+ if pkginit not in self ._collection_node_cache1 :
547
561
col = self ._collectfile (pkginit , handle_dupes = False )
548
562
if col :
549
563
if isinstance (col [0 ], Package ):
550
564
self ._collection_pkg_roots [parent ] = col [0 ]
551
565
# always store a list in the cache, matchnodes expects it
552
- self ._collection_node_cache [col [0 ].fspath ] = [col [0 ]]
566
+ self ._collection_node_cache1 [col [0 ].fspath ] = [col [0 ]]
553
567
554
568
# If it's a directory argument, recurse and look for any Subpackages.
555
569
# Let the Package collector deal with subnodes, don't collect here.
@@ -576,21 +590,21 @@ def _collect(self, argpath, names):
576
590
577
591
for x in self ._collectfile (path ):
578
592
key = (type (x ), x .fspath )
579
- if key in self ._collection_node_cache :
580
- yield self ._collection_node_cache [key ]
593
+ if key in self ._collection_node_cache2 :
594
+ yield self ._collection_node_cache2 [key ]
581
595
else :
582
- self ._collection_node_cache [key ] = x
596
+ self ._collection_node_cache2 [key ] = x
583
597
yield x
584
598
else :
585
599
assert argpath .check (file = 1 )
586
600
587
- if argpath in self ._collection_node_cache :
588
- col = self ._collection_node_cache [argpath ]
601
+ if argpath in self ._collection_node_cache1 :
602
+ col = self ._collection_node_cache1 [argpath ]
589
603
else :
590
604
collect_root = self ._collection_pkg_roots .get (argpath .dirname , self )
591
605
col = collect_root ._collectfile (argpath , handle_dupes = False )
592
606
if col :
593
- self ._collection_node_cache [argpath ] = col
607
+ self ._collection_node_cache1 [argpath ] = col
594
608
m = self .matchnodes (col , names )
595
609
# If __init__.py was the only file requested, then the matched node will be
596
610
# the corresponding Package, and the first yielded item will be the __init__
@@ -703,11 +717,11 @@ def _matchnodes(self, matching, names):
703
717
continue
704
718
assert isinstance (node , nodes .Collector )
705
719
key = (type (node ), node .nodeid )
706
- if key in self ._collection_node_cache :
707
- rep = self ._collection_node_cache [key ]
720
+ if key in self ._collection_node_cache3 :
721
+ rep = self ._collection_node_cache3 [key ]
708
722
else :
709
723
rep = collect_one_node (node )
710
- self ._collection_node_cache [key ] = rep
724
+ self ._collection_node_cache3 [key ] = rep
711
725
if rep .passed :
712
726
has_matched = False
713
727
for x in rep .result :
0 commit comments