Skip to content

Commit

Permalink
Move _collectfile to FSCollector (#6830)
Browse files Browse the repository at this point in the history
Previously this was implemented both on `Session` and `Package`, where
the extra code in `Package._collectfile` was not covered/used.

Ref: #6830 (comment)
  • Loading branch information
blueyed authored Feb 29, 2020
1 parent ff7b5db commit f10ab02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
22 changes: 0 additions & 22 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,28 +587,6 @@ def _collect(self, argpath, names):
return
yield from m

def _collectfile(self, path, handle_dupes=True):
assert (
path.isfile()
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
path, path.isdir(), path.exists(), path.islink()
)
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()

if handle_dupes:
keepduplicates = self.config.getoption("keepduplicates")
if not keepduplicates:
duplicate_paths = self.config.pluginmanager._duplicatepaths
if path in duplicate_paths:
return ()
else:
duplicate_paths.add(path)

return ihook.pytest_collect_file(path=path, parent=self)

@staticmethod
def _visit_filter(f):
return f.check(file=1)
Expand Down
22 changes: 22 additions & 0 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,28 @@ def _recurse(self, dirpath: py.path.local) -> bool:
ihook.pytest_collect_directory(path=dirpath, parent=self)
return True

def _collectfile(self, path, handle_dupes=True):
assert (
path.isfile()
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
path, path.isdir(), path.exists(), path.islink()
)
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()

if handle_dupes:
keepduplicates = self.config.getoption("keepduplicates")
if not keepduplicates:
duplicate_paths = self.config.pluginmanager._duplicatepaths
if path in duplicate_paths:
return ()
else:
duplicate_paths.add(path)

return ihook.pytest_collect_file(path=path, parent=self)


class File(FSCollector):
""" base class for collecting tests from a file. """
Expand Down
25 changes: 0 additions & 25 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,31 +593,6 @@ def setup(self):
def gethookproxy(self, fspath: py.path.local):
return super()._gethookproxy(fspath)

def _collectfile(self, path, handle_dupes=True):
assert (
path.isfile()
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
path, path.isdir(), path.exists(), path.islink()
)
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()

if handle_dupes:
keepduplicates = self.config.getoption("keepduplicates")
if not keepduplicates:
duplicate_paths = self.config.pluginmanager._duplicatepaths
if path in duplicate_paths:
return ()
else:
duplicate_paths.add(path)

if self.fspath == path: # __init__.py
return [self]

return ihook.pytest_collect_file(path=path, parent=self)

def isinitpath(self, path):
return path in self.session._initialpaths

Expand Down

0 comments on commit f10ab02

Please sign in to comment.