question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest.mark.only as debug marker to limit testsuite on existence

See original GitHub issue

Although 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:closed
  • Created 4 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
captain-karkcommented, Aug 10, 2019

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

1reaction
RonnyPfannschmidtcommented, Aug 7, 2019

maini question is wheether to provide this as a small plugin or directly in pytest

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with custom markers — pytest documentation
You can then restrict a test run to only run tests marked with webtest : ... You can ask which markers exist for...
Read more >
How to disable skipping a test in pytest without modifying ...
This only works if the test method is marked with skip not if the test class or module is marked. For this to...
Read more >
pytest Documentation
Will run all tests which are decorated with the @pytest.mark.slow ... and simplest fixture structure requires limiting fixtures to only ...
Read more >
9 pytest tips and tricks to take your tests to the next level
print("print message") if DEBUG_MODE: LOGGER.debug("Only in debug! ... [pytest] markers = slow: tests that run slowly ...
Read more >
Python Friday #50: Speed up Pytest With Markers
@pytest.mark.skip(reason=None): skip the given test function with an optional reason. Example: skip(reason=”no way of currently testing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found