pytest-only icon indicating copy to clipboard operation
pytest-only copied to clipboard

Support for mark.single to exclude even other mark.only tests

Open theY4Kman opened this issue 7 years ago • 0 comments

In a large codebase, I often set pytest.mark.only on the feature I'm working on, so I don't run the whole suite every time. However, there are a few times when I want to dig in to a single test. It'd be nice to not have to fall back to -k filter in those cases.

I've been playing with this for now:

def pytest_collection_modifyitems(config, items):
    single, only, other = [], [], []
    for item in items:
        if item.get_marker('single'):
            l = single
        elif item.get_marker('only'):
            l = only
        else:
            l = other
        l.append(item)

    if single:
        other += only
        only = single

    if only:
        items[:] = only
        if other:
            config.hook.pytest_deselected(items=other)

theY4Kman avatar Jul 30 '18 23:07 theY4Kman