Skip to content

Commit 576997a

Browse files
fix Package.from_parent, UNTESTED
1 parent 5203824 commit 576997a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/_pytest/python.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,27 @@ def _importtestmodule(self):
621621

622622

623623
class Package(Module):
624+
@classmethod
625+
def from_parent(
626+
cls,
627+
parent,
628+
*,
629+
name=None,
630+
fs_path: Optional[Path] = None,
631+
fspath: Optional[py.path.local] = None,
632+
**kw,
633+
):
634+
if name is None:
635+
if fs_path is not None:
636+
name = fs_path.parent.name
637+
elif fspath is not None:
638+
fs_path = Path(fspath)
639+
name = fs_path.parent.name
640+
else:
641+
raise TypeError("name required")
642+
643+
return super().from_parent(parent=parent, name=name, fs_path=fs_path, **kw)
644+
624645
def setup(self) -> None:
625646
# Not using fixtures to call setup_module here because autouse fixtures
626647
# from packages are not called automatically (#4085).

0 commit comments

Comments
 (0)