@@ -517,8 +517,19 @@ def _collect(self, arg):
517517 # Let the Package collector deal with subnodes, don't collect here.
518518 if argpath .check (dir = 1 ):
519519 assert not names , "invalid arg %r" % (arg ,)
520+
521+ if six .PY2 :
522+
523+ def filter_ (f ):
524+ return f .check (file = 1 ) and not f .strpath .endswith ("*.pyc" )
525+
526+ else :
527+
528+ def filter_ (f ):
529+ return f .check (file = 1 )
530+
520531 for path in argpath .visit (
521- fil = lambda x : x . check ( file = 1 ) , rec = self ._recurse , bf = True , sort = True
532+ fil = filter_ , rec = self ._recurse , bf = True , sort = True
522533 ):
523534 pkginit = path .dirpath ().join ("__init__.py" )
524535 if pkginit .exists () and not any (x in pkginit .parts () for x in paths ):
@@ -562,15 +573,17 @@ def _collectfile(self, path):
562573
563574 return ihook .pytest_collect_file (path = path , parent = self )
564575
565- def _recurse (self , path ):
566- ihook = self .gethookproxy (path .dirpath ())
567- if ihook .pytest_ignore_collect (path = path , config = self .config ):
568- return
576+ def _recurse (self , dirpath ):
577+ if dirpath .basename == "__pycache__" :
578+ return False
579+ ihook = self .gethookproxy (dirpath .dirpath ())
580+ if ihook .pytest_ignore_collect (path = dirpath , config = self .config ):
581+ return False
569582 for pat in self ._norecursepatterns :
570- if path .check (fnmatch = pat ):
583+ if dirpath .check (fnmatch = pat ):
571584 return False
572- ihook = self .gethookproxy (path )
573- ihook .pytest_collect_directory (path = path , parent = self )
585+ ihook = self .gethookproxy (dirpath )
586+ ihook .pytest_collect_directory (path = dirpath , parent = self )
574587 return True
575588
576589 def _tryconvertpyarg (self , x ):
0 commit comments