pytest.mark.only as debug marker to limit testsuite on existence
See original GitHub issueAlthough it’s not much work to put this into a conftest.py
file, I’ve put this into nearly every pytest project I’ve touched, and wouldn’t mind publishing it if it weren’t so small.
Do you think it would belong in the standard marks? It would complement pytest.mark.skip
, but would be the inverse. It’s useful for when you’ve isolated a small batch of tests in a single file for quick debugging or troubleshooting, to be removed before committing. It’s faster than updating a config file, or updating a test run through command line switches.
See https://mochajs.org/#exclusive-tests for prior art, and where I first encountered this pattern. Note at the bottom of the section, it says:
Be mindful not to commit usages of
.only()
to version control, unless you really mean it! To do so one can run mocha with the option --forbid-only in the continuous integration test command (or in a git precommit hook).
The implementation I use is simple enough as a top-level conftest.py
hook, but honestly I’m not sure how well it would behave as a generally available mark. Things like pytest.mark.parameterize
could make this tricky, as an example.
def pytest_collection_modifyitems(session, config, items):
items = [item for item in items if 'only' in [m.name for m in item.own_markers]]
def test_one():
assert True
@pytest.mark.only
def test_two():
assert False
def test_three():
assert True
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (12 by maintainers)
Weird, I thought I searched for this before filing this issue, but I guess I didn’t look hard enough…?
https://github.com/theY4Kman/pytest-only
maini question is wheether to provide this as a small plugin or directly in pytest