Skip to content

fix: propagate package-level pytestmark from __init__.py#14740

Closed
Solaris-star wants to merge 2 commits into
pytest-dev:mainfrom
Solaris-star:fix/14737-package-pytestmark-propagation
Closed

fix: propagate package-level pytestmark from __init__.py#14740
Solaris-star wants to merge 2 commits into
pytest-dev:mainfrom
Solaris-star:fix/14737-package-pytestmark-propagation

Conversation

@Solaris-star

Copy link
Copy Markdown

Description

A package-level marker in __init__.py used to apply to tests under that package. After Package stopped being a Module/File, those markers were never loaded into own_markers, so tests ran instead of being skipped/xfailed.

Fix

In Package.collect(), import __init__.py via importtestmodule and apply get_unpacked_marks(init_mod) to the package node's own_markers / keywords. Children inherit markers through parent walk in iter_markers_with_node.

Test

pytest testing/test_mark.py::test_package_level_pytestmark_propagates -q
# 1 passed

Linked Issue

Closes #14737

Solaris-star and others added 2 commits July 21, 2026 11:26
After Package stopped being a Module/File, pytestmark defined in a
package __init__.py was no longer applied to contained tests, so
package-level skip/xfail markers were ignored.

Load __init__.py during Package.collect and extend own_markers/keywords
from get_unpacked_marks, matching Module/PyCollector behaviour.

Fixes pytest-dev#14737
@The-Compiler

Copy link
Copy Markdown
Member

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