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