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