💡 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_*andonly_*are recognised (e.g.@pytest.mark.ONLY_smokeand@pytest.mark.only_smokeare equivalent) - ✅ 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>(or@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: 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!
Release files for pytest-only-markers 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_only_markers-1.0.1.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_only_markers-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:10.2 kB
Release files / pytest_only_markers-1.0.1.tar.gz
| Download URL | pytest_only_markers-1.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
904d2d1df79cd9db1f459134bcb3fa36cf2a1f9635a4b9a41de89efaf95150b9
|
|
BLAKE2b-256 checksum How to use checksums |
5d09fe4ef0aa13d83d516d101cf4769b67a252dfbdcea465f549e9b9ef3fc698
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pytest_only_markers-1.0.1-py3-none-any.whl
| Download URL | pytest_only_markers-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63b35fdb41331e6af81918e7ddd1c606e51d0a7876f8fdd0120b364f86da15ae
|
|
BLAKE2b-256 checksum How to use checksums |
21057a317fab0e8802158714aa933d32b3a590d5c99a975c83941ca0d585b69d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|