Skip to content

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

Description

@SuYanqi

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.

This is a regression introduced by PR #6197.

pytest and operating system versions

pytest 9.1.1
Python 3.11.13
Linux

minimal example if possible

from pathlib import Path
import shutil
import pytest

root = Path("/tmp/pytest_pkg_skip_test")
shutil.rmtree(root, ignore_errors=True)
package = root / "skippedpkg"
package.mkdir(parents=True)
(package / "__init__.py").write_text(
    "import pytest\n"
    "pytestmark = pytest.mark.skip(reason='package is disabled')\n"
)
(package / "test_skipped.py").write_text(
    "def test_should_be_skipped():\n"
    "    assert False\n"
)

result = pytest.main(["-q", str(package)])
print("exit code:", int(result))
shutil.rmtree(root, ignore_errors=True)

Expected: 1 skipped, exit code 0
Actual: 1 failed (assert False runs because skip marker is not applied), exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions