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: https://github.com/pytest-dev/pytest/pull/6830#issuecomment-592663236
This commit is contained in:
parent
ff7b5dbbde
commit
f10ab021e2
|
@ -587,28 +587,6 @@ class Session(nodes.FSCollector):
|
||||||
return
|
return
|
||||||
yield from m
|
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
|
@staticmethod
|
||||||
def _visit_filter(f):
|
def _visit_filter(f):
|
||||||
return f.check(file=1)
|
return f.check(file=1)
|
||||||
|
|
|
@ -502,6 +502,28 @@ class FSCollector(Collector):
|
||||||
ihook.pytest_collect_directory(path=dirpath, parent=self)
|
ihook.pytest_collect_directory(path=dirpath, parent=self)
|
||||||
return True
|
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):
|
class File(FSCollector):
|
||||||
""" base class for collecting tests from a file. """
|
""" base class for collecting tests from a file. """
|
||||||
|
|
|
@ -593,31 +593,6 @@ class Package(Module):
|
||||||
def gethookproxy(self, fspath: py.path.local):
|
def gethookproxy(self, fspath: py.path.local):
|
||||||
return super()._gethookproxy(fspath)
|
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):
|
def isinitpath(self, path):
|
||||||
return path in self.session._initialpaths
|
return path in self.session._initialpaths
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue