From 9533214a18a1959509df6759711b862750444623 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Tue, 28 Jul 2026 22:26:59 +0800 Subject: [PATCH] fix: propagate pytestmark from __init__.py to Package collector --- src/_pytest/python.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 4f168012c36..8b8086215b5 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -696,6 +696,12 @@ def __init__( def setup(self) -> None: init_mod = importtestmodule(self.path / "__init__.py", self.config) + # Read pytestmark from the __init__.py module. + init_marks = get_unpacked_marks(init_mod) + if init_marks: + self.own_markers.extend(init_marks) + self.keywords.update((mark.name, mark) for mark in init_marks) + # Not using fixtures to call setup_module here because autouse fixtures # from packages are not called automatically (#4085). setup_module = _get_first_non_fixture_func(