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_ (case-insensitive: ONLY_ or 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
  • Case-insensitive prefix — both ONLY_* and only_* are recognised (e.g. @pytest.mark.ONLY_smoke and @pytest.mark.only_smoke are equivalent)
  • 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> (or @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: Case-insensitive prefix

import pytest

@pytest.mark.only_smoke   # lowercase — works the same as ONLY_smoke
def test_ping():
    assert True

@pytest.mark.ONLY_smoke   # uppercase — equivalent
def test_pong():
    assert True

Example 4: 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.1.tar.gz (5.0 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.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_only_markers-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 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.1.tar.gz
Algorithm Hash digest
SHA256 904d2d1df79cd9db1f459134bcb3fa36cf2a1f9635a4b9a41de89efaf95150b9
MD5 0810401c0d9be5c90c9de9c935b1566f
BLAKE2b-256 5d09fe4ef0aa13d83d516d101cf4769b67a252dfbdcea465f549e9b9ef3fc698

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_only_markers-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63b35fdb41331e6af81918e7ddd1c606e51d0a7876f8fdd0120b364f86da15ae
MD5 eb28044c6ad92ae709f743afe7e7de7d
BLAKE2b-256 21057a317fab0e8802158714aa933d32b3a590d5c99a975c83941ca0d585b69d

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