8
8
from typing import Dict
9
9
from typing import FrozenSet
10
10
from typing import List
11
+ from typing import Tuple
11
12
12
13
import attr
13
14
import py
@@ -486,13 +487,13 @@ def _perform_collect(self, args, genitems):
486
487
self .trace ("perform_collect" , self , args )
487
488
self .trace .root .indent += 1
488
489
self ._notfound = []
489
- initialpaths = []
490
- self ._initialparts = []
490
+ initialpaths = [] # type: List[py.path.local]
491
+ self ._initial_parts = [] # type: List[Tuple[py.path.local, List[str]] ]
491
492
self .items = items = []
492
493
for arg in args :
493
- parts = self ._parsearg (arg )
494
- self ._initialparts .append (parts )
495
- initialpaths .append (parts [ 0 ] )
494
+ fspath , parts = self ._parsearg (arg )
495
+ self ._initial_parts .append (( fspath , parts ) )
496
+ initialpaths .append (fspath )
496
497
self ._initialpaths = frozenset (initialpaths )
497
498
rep = collect_one_node (self )
498
499
self .ihook .pytest_collectreport (report = rep )
@@ -512,13 +513,13 @@ def _perform_collect(self, args, genitems):
512
513
return items
513
514
514
515
def collect (self ):
515
- for initialpart in self ._initialparts :
516
- self .trace ("processing argument" , initialpart )
516
+ for fspath , parts in self ._initial_parts :
517
+ self .trace ("processing argument" , ( fspath , parts ) )
517
518
self .trace .root .indent += 1
518
519
try :
519
- yield from self ._collect (initialpart )
520
+ yield from self ._collect (fspath , parts )
520
521
except NoMatch :
521
- report_arg = "::" .join (map (str , initialpart ))
522
+ report_arg = "::" .join ((str ( fspath ), * parts ))
522
523
# we are inside a make_report hook so
523
524
# we cannot directly pass through the exception
524
525
self ._notfound .append ((report_arg , sys .exc_info ()[1 ]))
@@ -527,12 +528,9 @@ def collect(self):
527
528
self ._collection_node_cache .clear ()
528
529
self ._collection_pkg_roots .clear ()
529
530
530
- def _collect (self , arg ):
531
+ def _collect (self , argpath , names ):
531
532
from _pytest .python import Package
532
533
533
- names = arg [:]
534
- argpath = names .pop (0 )
535
-
536
534
# Start with a Session root, and delve to argpath item (dir or file)
537
535
# and stack all Packages found on the way.
538
536
# No point in finding packages when collecting doctests
@@ -556,7 +554,7 @@ def _collect(self, arg):
556
554
# If it's a directory argument, recurse and look for any Subpackages.
557
555
# Let the Package collector deal with subnodes, don't collect here.
558
556
if argpath .check (dir = 1 ):
559
- assert not names , "invalid arg {!r}" .format (arg )
557
+ assert not names , "invalid arg {!r}" .format (( argpath , names ) )
560
558
561
559
seen_dirs = set ()
562
560
for path in argpath .visit (
@@ -666,19 +664,19 @@ def _tryconvertpyarg(self, x):
666
664
667
665
def _parsearg (self , arg ):
668
666
""" return (fspath, names) tuple after checking the file exists. """
669
- parts = str (arg ).split ("::" )
667
+ strpath , * parts = str (arg ).split ("::" )
670
668
if self .config .option .pyargs :
671
- parts [ 0 ] = self ._tryconvertpyarg (parts [ 0 ] )
672
- relpath = parts [ 0 ] .replace ("/" , os .sep )
673
- path = self .config .invocation_dir .join (relpath , abs = True )
674
- if not path .check ():
669
+ strpath = self ._tryconvertpyarg (strpath )
670
+ relpath = strpath .replace ("/" , os .sep )
671
+ fspath = self .config .invocation_dir .join (relpath , abs = True )
672
+ if not fspath .check ():
675
673
if self .config .option .pyargs :
676
674
raise UsageError (
677
675
"file or package not found: " + arg + " (missing __init__.py?)"
678
676
)
679
677
raise UsageError ("file not found: " + arg )
680
- parts [ 0 ] = path .realpath ()
681
- return parts
678
+ fspath = fspath .realpath ()
679
+ return ( fspath , parts )
682
680
683
681
def matchnodes (self , matching , names ):
684
682
self .trace ("matchnodes" , matching , names )
0 commit comments