A pytest plugin that isolates test execution to only tests decorated with ONLY_* markers, stripping all other markers from matching items.
Project description
💡 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-levelpytestmark) are stripped from matching items - ✅ Transparent deselection — skipped tests appear in pytest's
x deselectedsummary, not silently dropped - ✅ Instance-level patch —
iter_markersis patched per item so downstream plugins see onlyONLY_*markers - ✅ Opt-in via flag — behaviour is disabled by default; activate with
--only-markers-prefix
🛠️ How to Use
- Install the plugin via
uv add pytest-only-markers - Enable it by adding
--only-markers-prefixto yourpytest.inior passing it on the CLI - Decorate any test with
@pytest.mark.ONLY_<name>to mark it for isolated execution - 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59efcfd9fb14fc4936d21f2fc937827c1b62fa200c86380c3ba9a4c7a169d81d
|
|
| MD5 |
5616a5885fc7ee9d3f4d7caf7da8e1fb
|
|
| BLAKE2b-256 |
7167167d09dabae8bc4d14d52ed2894960cbfb0a626cb4041b74a94a29c6c9bb
|
File details
Details for the file pytest_only_markers-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_only_markers-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f0908d7dc151925fca364a9226bc11988caf0afd7429c7aa0b89dd004d455a5
|
|
| MD5 |
6ca57e4b170c4664133d54b2e04b05c9
|
|
| BLAKE2b-256 |
053389c2ae1795b5211ffbc37dc32f65d20bae7d2b1d98fa6ad5f31eb4391e9f
|