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