Last active
February 1, 2016 22:55
-
-
Save hackebrot/05f42c78a069bbb16233 to your computer and use it in GitHub Desktop.
pytest magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pytest_collection_modifyitems(items, config): | |
selected_items = [] | |
deselected_items = [] | |
for item in items: | |
if 'new_fixture' in getattr(item, 'fixturenames', ()): | |
selected_items.append(item) | |
else: | |
deselected_items.append(item) | |
config.hook.pytest_deselected(items=deselected_items) | |
items[:] = selected_items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.fixture | |
def new_fixture(): | |
return 'foobar' | |
@pytest.fixture | |
def another_fixture(new_fixture): | |
return 'foobar' | |
def test_abc(new_fixture): | |
assert True | |
def test_def(another_fixture): | |
assert False | |
def test_that_does_not_use_fixture(): | |
assert False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment