From baaa67dfb91444a58b28806bb6719a337454c4bb Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 19 May 2023 14:56:37 +0300 Subject: [PATCH] python: simplify code in Package.collect() The path of Package is already the `__init__.py` file, and we're already assured it's a file. --- src/_pytest/python.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index d04b6fa4d..9b9d0b7c6 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -745,11 +745,11 @@ class Package(Module): def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]: this_path = self.path.parent - init_module = this_path / "__init__.py" - if init_module.is_file() and path_matches_patterns( - init_module, self.config.getini("python_files") - ): - yield Module.from_parent(self, path=init_module) + + # Always collect the __init__ first. + if path_matches_patterns(self.path, self.config.getini("python_files")): + yield Module.from_parent(self, path=self.path) + pkg_prefixes: Set[Path] = set() for direntry in visit(str(this_path), recurse=self._recurse): path = Path(direntry.path)