Skip to content

Commit 64ce7f0

Browse files
authored
Move _collectfile to FSCollector (#259)
Previously this was implemented both on `Session` and `Package`, where the extra code in `Package._collectfile` was not covered/used.
1 parent e99178f commit 64ce7f0

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
@@ -610,28 +610,6 @@ def _collect(self, argpath, names):
610610
return
611611
yield from m
612612

613-
def _collectfile(self, path, handle_dupes=True):
614-
assert (
615-
path.isfile()
616-
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
617-
path, path.isdir(), path.exists(), path.islink()
618-
)
619-
ihook = self.gethookproxy(path)
620-
if not self.isinitpath(path):
621-
if ihook.pytest_ignore_collect(path=path, config=self.config):
622-
return ()
623-
624-
if handle_dupes:
625-
keepduplicates = self.config.getoption("keepduplicates")
626-
if not keepduplicates:
627-
duplicate_paths = self.config.pluginmanager._duplicatepaths
628-
if path in duplicate_paths:
629-
return ()
630-
else:
631-
duplicate_paths.add(path)
632-
633-
return ihook.pytest_collect_file(path=path, parent=self)
634-
635613
@staticmethod
636614
def _visit_filter(f):
637615
return f.check(file=1)

src/_pytest/nodes.py

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

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

510532
class File(FSCollector):
511533
""" 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
@@ -595,31 +595,6 @@ def setup(self):
595595
def gethookproxy(self, fspath: py.path.local):
596596
return super()._gethookproxy(fspath)
597597

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

0 commit comments

Comments
 (0)