Skip to content

Commit f10ab02

Browse files
authored
Move _collectfile to FSCollector (#6830)
Previously this was implemented both on `Session` and `Package`, where the extra code in `Package._collectfile` was not covered/used. Ref: #6830 (comment)
1 parent ff7b5db commit f10ab02

File tree

3 files changed

+22
-47
lines changed

3 files changed

+22
-47
lines changed

src/_pytest/main.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -587,28 +587,6 @@ def _collect(self, argpath, names):
587587
return
588588
yield from m
589589

590-
def _collectfile(self, path, handle_dupes=True):
591-
assert (
592-
path.isfile()
593-
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
594-
path, path.isdir(), path.exists(), path.islink()
595-
)
596-
ihook = self.gethookproxy(path)
597-
if not self.isinitpath(path):
598-
if ihook.pytest_ignore_collect(path=path, config=self.config):
599-
return ()
600-
601-
if handle_dupes:
602-
keepduplicates = self.config.getoption("keepduplicates")
603-
if not keepduplicates:
604-
duplicate_paths = self.config.pluginmanager._duplicatepaths
605-
if path in duplicate_paths:
606-
return ()
607-
else:
608-
duplicate_paths.add(path)
609-
610-
return ihook.pytest_collect_file(path=path, parent=self)
611-
612590
@staticmethod
613591
def _visit_filter(f):
614592
return f.check(file=1)

src/_pytest/nodes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,28 @@ def _recurse(self, dirpath: py.path.local) -> bool:
502502
ihook.pytest_collect_directory(path=dirpath, parent=self)
503503
return True
504504

505+
def _collectfile(self, path, handle_dupes=True):
506+
assert (
507+
path.isfile()
508+
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
509+
path, path.isdir(), path.exists(), path.islink()
510+
)
511+
ihook = self.gethookproxy(path)
512+
if not self.isinitpath(path):
513+
if ihook.pytest_ignore_collect(path=path, config=self.config):
514+
return ()
515+
516+
if handle_dupes:
517+
keepduplicates = self.config.getoption("keepduplicates")
518+
if not keepduplicates:
519+
duplicate_paths = self.config.pluginmanager._duplicatepaths
520+
if path in duplicate_paths:
521+
return ()
522+
else:
523+
duplicate_paths.add(path)
524+
525+
return ihook.pytest_collect_file(path=path, parent=self)
526+
505527

506528
class File(FSCollector):
507529
""" base class for collecting tests from a file. """

src/_pytest/python.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -593,31 +593,6 @@ def setup(self):
593593
def gethookproxy(self, fspath: py.path.local):
594594
return super()._gethookproxy(fspath)
595595

596-
def _collectfile(self, path, handle_dupes=True):
597-
assert (
598-
path.isfile()
599-
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
600-
path, path.isdir(), path.exists(), path.islink()
601-
)
602-
ihook = self.gethookproxy(path)
603-
if not self.isinitpath(path):
604-
if ihook.pytest_ignore_collect(path=path, config=self.config):
605-
return ()
606-
607-
if handle_dupes:
608-
keepduplicates = self.config.getoption("keepduplicates")
609-
if not keepduplicates:
610-
duplicate_paths = self.config.pluginmanager._duplicatepaths
611-
if path in duplicate_paths:
612-
return ()
613-
else:
614-
duplicate_paths.add(path)
615-
616-
if self.fspath == path: # __init__.py
617-
return [self]
618-
619-
return ihook.pytest_collect_file(path=path, parent=self)
620-
621596
def isinitpath(self, path):
622597
return path in self.session._initialpaths
623598

0 commit comments

Comments
 (0)