Skip to content

fix: propagate pytestmark from __init__.py to Package collector - #14798

Closed
waterWang wants to merge 1 commit into
pytest-dev:mainfrom
waterWang:fix/package-pytestmark-init-py
Closed

fix: propagate pytestmark from __init__.py to Package collector#14798
waterWang wants to merge 1 commit into
pytest-dev:mainfrom
waterWang:fix/package-pytestmark-init-py

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #14737

Problem

When a pytestmark is defined in a package's __init__.py, it is no longer propagated to tests within that package. This worked in earlier versions but was broken by a refactoring.

Root Cause

Package.setup() imports the __init__.py module via importtestmodule() but never reads the pytestmark attribute from it. The get_unpacked_marks() function (already imported) is used elsewhere (e.g., in PyobjMixin._filter_with_own_markers) to extract marks from module objects, but was never called for the __init__.py module in Package.setup().

Fix

Added get_unpacked_marks(init_mod) call in Package.setup() after importing the __init__.py module. The extracted marks are added to self.own_markers and self.keywords, which is consistent with how other collectors handle marks (see PyobjMixin at line 313 and FunctionDefinition.__init__ at line 1709).

Testing

  • pytestmark = pytest.mark.skip(reason="package skip") in __init__.py now correctly skips tests in the package
  • iter_markers() on package-level markers now includes marks from __init__.py
  • All existing tests should pass as this is purely additive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package-level pytestmark in __init__.py no longer propagates to tests

2 participants