You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Package-level pytestmark in __init__.py no longer propagates to tests #14737
a detailed description of the bug or problem you are having
A package-level pytestmark = pytest.mark.skip(...) defined in __init__.py is no longer propagated to tests inside that package. Tests that should be skipped run and fail instead.
I can reproduce this, but I do not think it is a regression - the behaviour looks unchanged for as far back as I tested, so the fix is probably a policy decision rather than a straight bug fix.
Reproduction
Your script reproduces on current main (56b196e92): 1 failed, exit 1, where you expected 1 skipped.
Version matrix
I ran the same package against released versions in clean virtualenvs, so the only variable is the pytest version:
#6197 is in the history as 19a15a94e, "Fix incorrect discovery of non-test __init__.py files" (Nov 2019), and the changelog records it as:
:issue:6197: Revert "The first test in a package (__init__.py) marked with @pytest.mark.skip is now correctly skipped."
That commit removed 24 lines from src/_pytest/python.py and deleted the corresponding test from testing/test_skipping.py, in order to fix #6194. So the current behaviour was chosen deliberately roughly six years ago as the cost of not collecting non-test __init__.py files - it is the intended state of the code, not something that drifted.
Why I stopped short of a patch
Restoring propagation means collecting __init__.py as a module again in some form, which is the thing #6197 was written to stop. A patch that simply re-applies the reverted behaviour would likely reintroduce #6194, so this needs a maintainer's call on which of two documented behaviours wins.
If the desired outcome is that package-level marks apply, I would be glad to implement whichever direction you prefer:
Collect marks from __init__.py without collecting it as a test module - read pytestmark from the package during Package collection and fold it into the child modules' marks, leaving discovery untouched.
Document the current behaviour instead, since conftest.py already provides a supported way to apply marks package-wide (pytestmark in conftest.py, or pytest_collection_modifyitems), and close this as working-as-intended.
Option 1 keeps the reporter's expectation and avoids #6194 because nothing new is collected, only marks are read - but I did not want to assume that is wanted given the explicit revert.
Activity
Zuhef commentedon Jul 29, 2026
I can reproduce this, but I do not think it is a regression - the behaviour looks unchanged for as far back as I tested, so the fix is probably a policy decision rather than a straight bug fix.
Reproduction
Your script reproduces on current
main(56b196e92):1 failed, exit 1, where you expected1 skipped.Version matrix
I ran the same package against released versions in clean virtualenvs, so the only variable is the pytest version:
1 failed1 failed1 failedmain(56b196e)1 failedThe marker is ignored in all of them, so there is no version where this worked that a bisect could land between.
Why #6197 is not quite the culprit
#6197 is in the history as
19a15a94e, "Fix incorrect discovery of non-test__init__.pyfiles" (Nov 2019), and the changelog records it as:That commit removed 24 lines from
src/_pytest/python.pyand deleted the corresponding test fromtesting/test_skipping.py, in order to fix #6194. So the current behaviour was chosen deliberately roughly six years ago as the cost of not collecting non-test__init__.pyfiles - it is the intended state of the code, not something that drifted.Why I stopped short of a patch
Restoring propagation means collecting
__init__.pyas a module again in some form, which is the thing #6197 was written to stop. A patch that simply re-applies the reverted behaviour would likely reintroduce #6194, so this needs a maintainer's call on which of two documented behaviours wins.If the desired outcome is that package-level marks apply, I would be glad to implement whichever direction you prefer:
__init__.pywithout collecting it as a test module - readpytestmarkfrom the package duringPackagecollection and fold it into the child modules' marks, leaving discovery untouched.conftest.pyalready provides a supported way to apply marks package-wide (pytestmarkinconftest.py, orpytest_collection_modifyitems), and close this as working-as-intended.Option 1 keeps the reporter's expectation and avoids #6194 because nothing new is collected, only marks are read - but I did not want to assume that is wanted given the explicit revert.
aryansk commentedon Aug 20, 2026
python: apply pytestmark from a package's __init__.py