Skip to main content

A pytest plugin that isolates test execution to only tests decorated with ONLY_* markers, stripping all other markers from matching items.

Project description

PyPI version Python Development Status Maintenance PyPI License


💡 pytest-only-markers

A pytest plugin that lets you isolate specific tests using ONLY_* markers. When any test is decorated with a marker prefixed ONLY_, only those tests are collected and run — all other tests (and their inherited pytestmark markers) are suppressed.


📦 Installation

uv add pytest-only-markers

🚀 Features

  • Selective collection — only tests carrying an ONLY_* marker are collected; all others are deselected
  • Marker isolation — non-ONLY_* markers (including module-level pytestmark) are stripped from matching items
  • Transparent deselection — skipped tests appear in pytest's x deselected summary, not silently dropped
  • Instance-level patchiter_markers is patched per item so downstream plugins see only ONLY_* markers
  • Opt-in via flag — behaviour is disabled by default; activate with --only-markers-prefix

🛠️ How to Use

  1. Install the plugin via uv add pytest-only-markers
  2. Enable it by adding --only-markers-prefix to your pytest.ini or passing it on the CLI
  3. Decorate any test with @pytest.mark.ONLY_<name> to mark it for isolated execution
  4. Run pytest — only tests with ONLY_* markers will be collected and executed

🚀 Quick Start

Add to pytest.ini:

[pytest]
addopts = --only-markers-prefix
markers =
    ONLY_smoke: Run only smoke tests
    ONLY_api: Run only API tests

Then tag your tests:

pytestmark = [pytest.mark.regression, pytest.mark.slow]

@pytest.mark.ONLY_smoke
def test_health_check():
    ...
# Collected and run — effective markers: ONLY_smoke only

def test_full_flow():
    ...
# Deselected — no ONLY_* marker

▶️ Usage Examples

Example 1: Single ONLY_ marker

import pytest

pytestmark = [pytest.mark.regression, pytest.mark.slow]

@pytest.mark.ONLY_smoke
def test_ping():
    assert True
# Result: collected, runs with only ONLY_smoke marker
# test_heavy and test_regression are deselected

Example 2: Multiple ONLY_ markers on one test

import pytest

pytestmark = [pytest.mark.dummy]

@pytest.mark.ONLY_api
@pytest.mark.ONLY_smoke
def test_create_user():
    assert True
# Result: collected, effective markers are ONLY_api + ONLY_smoke
# pytestmark (dummy) is stripped

Example 3: CLI usage without modifying pytest.ini

pytest --only-markers-prefix tests/

🤝 Contributing

If you have a helpful pattern or improvement to suggest: Fork the repo Create a new branch Submit a pull request I welcome additions that promote clean, productive, and maintainable development.


📄 License

MIT License — see LICENSE for details.


🙏 Thanks

Thanks for exploring this repository!
Happy coding!

GitHub   PyPI   Blog   LinkedIn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_only_markers-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_only_markers-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_only_markers-1.0.0.tar.gz.

File metadata

  • Download URL: pytest_only_markers-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_only_markers-1.0.0.tar.gz
Algorithm Hash digest
SHA256 59efcfd9fb14fc4936d21f2fc937827c1b62fa200c86380c3ba9a4c7a169d81d
MD5 5616a5885fc7ee9d3f4d7caf7da8e1fb
BLAKE2b-256 7167167d09dabae8bc4d14d52ed2894960cbfb0a626cb4041b74a94a29c6c9bb

See more details on using hashes here.

File details

Details for the file pytest_only_markers-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_only_markers-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f0908d7dc151925fca364a9226bc11988caf0afd7429c7aa0b89dd004d455a5
MD5 6ca57e4b170c4664133d54b2e04b05c9
BLAKE2b-256 053389c2ae1795b5211ffbc37dc32f65d20bae7d2b1d98fa6ad5f31eb4391e9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page