From a550db4b6c8c809d6cbf42c11c428da40d3f247e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 20 Mar 2021 21:50:40 +0100 Subject: [PATCH] drop internal py.path.local objects from hook calls --- src/_pytest/main.py | 10 +++------- src/_pytest/python.py | 18 +++++------------- src/_pytest/terminal.py | 3 +-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 97a14ea59..ffe8b852c 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -563,9 +563,8 @@ class Session(nodes.FSCollector): if direntry.name == "__pycache__": return False fspath = Path(direntry.path) - path = legacy_path(fspath) ihook = self.gethookproxy(fspath.parent) - if ihook.pytest_ignore_collect(fspath=fspath, path=path, config=self.config): + if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): return False norecursepatterns = self.config.getini("norecursedirs") if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns): @@ -575,7 +574,6 @@ class Session(nodes.FSCollector): def _collectfile( self, fspath: Path, handle_dupes: bool = True ) -> Sequence[nodes.Collector]: - path = legacy_path(fspath) assert ( fspath.is_file() ), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format( @@ -583,9 +581,7 @@ class Session(nodes.FSCollector): ) ihook = self.gethookproxy(fspath) if not self.isinitpath(fspath): - if ihook.pytest_ignore_collect( - fspath=fspath, path=path, config=self.config - ): + if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): return () if handle_dupes: @@ -597,7 +593,7 @@ class Session(nodes.FSCollector): else: duplicate_paths.add(fspath) - return ihook.pytest_collect_file(fspath=fspath, path=path, parent=self) # type: ignore[no-any-return] + return ihook.pytest_collect_file(fspath=fspath, parent=self) # type: ignore[no-any-return] @overload def perform_collect( diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 04fbb4570..652c72123 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -188,9 +188,7 @@ def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]: return True -def pytest_collect_file( - fspath: Path, path: LEGACY_PATH, parent: nodes.Collector -) -> Optional["Module"]: +def pytest_collect_file(fspath: Path, parent: nodes.Collector) -> Optional["Module"]: if fspath.suffix == ".py": if not parent.session.isinitpath(fspath): if not path_matches_patterns( @@ -198,9 +196,7 @@ def pytest_collect_file( ): return None ihook = parent.session.gethookproxy(fspath) - module: Module = ihook.pytest_pycollect_makemodule( - fspath=fspath, path=path, parent=parent - ) + module: Module = ihook.pytest_pycollect_makemodule(fspath=fspath, parent=parent) return module return None @@ -675,9 +671,8 @@ class Package(Module): if direntry.name == "__pycache__": return False fspath = Path(direntry.path) - path = legacy_path(fspath) ihook = self.session.gethookproxy(fspath.parent) - if ihook.pytest_ignore_collect(fspath=fspath, path=path, config=self.config): + if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): return False norecursepatterns = self.config.getini("norecursedirs") if any(fnmatch_ex(pat, fspath) for pat in norecursepatterns): @@ -687,7 +682,6 @@ class Package(Module): def _collectfile( self, fspath: Path, handle_dupes: bool = True ) -> Sequence[nodes.Collector]: - path = legacy_path(fspath) assert ( fspath.is_file() ), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format( @@ -695,9 +689,7 @@ class Package(Module): ) ihook = self.session.gethookproxy(fspath) if not self.session.isinitpath(fspath): - if ihook.pytest_ignore_collect( - fspath=fspath, path=path, config=self.config - ): + if ihook.pytest_ignore_collect(fspath=fspath, config=self.config): return () if handle_dupes: @@ -709,7 +701,7 @@ class Package(Module): else: duplicate_paths.add(fspath) - return ihook.pytest_collect_file(fspath=fspath, path=path, parent=self) # type: ignore[no-any-return] + return ihook.pytest_collect_file(fspath=fspath, parent=self) # type: ignore[no-any-return] def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]: this_path = self.path.parent diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 2c95113e5..252f898bf 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -716,7 +716,7 @@ class TerminalReporter: msg += " -- " + str(sys.executable) self.write_line(msg) lines = self.config.hook.pytest_report_header( - config=self.config, startpath=self.startpath, startdir=self.startdir + config=self.config, startpath=self.startpath ) self._write_report_lines_from_hooks(lines) @@ -753,7 +753,6 @@ class TerminalReporter: lines = self.config.hook.pytest_report_collectionfinish( config=self.config, startpath=self.startpath, - startdir=self.startdir, items=session.items, ) self._write_report_lines_from_hooks(lines)