Skip to content

Commit baaa67d

Browse files
committed
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.
1 parent 519f351 commit baaa67d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/_pytest/python.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,11 @@ def _collectfile(
745745

746746
def collect(self) -> Iterable[Union[nodes.Item, nodes.Collector]]:
747747
this_path = self.path.parent
748-
init_module = this_path / "__init__.py"
749-
if init_module.is_file() and path_matches_patterns(
750-
init_module, self.config.getini("python_files")
751-
):
752-
yield Module.from_parent(self, path=init_module)
748+
749+
# Always collect the __init__ first.
750+
if path_matches_patterns(self.path, self.config.getini("python_files")):
751+
yield Module.from_parent(self, path=self.path)
752+
753753
pkg_prefixes: Set[Path] = set()
754754
for direntry in visit(str(this_path), recurse=self._recurse):
755755
path = Path(direntry.path)

0 commit comments

Comments
 (0)