Reputation: 3078
Let's say I have a fixture that requires a live database.
If the live database doesn't exist, I want to skip tests that depend on that fixture.
At the moment, I have to manually mark tests to skip, which feels redundant:
@pytest.fixture
def db_client():
DB_URI = os.getenv('DB_URI')
# Set up DB client and yield it
@pytest.mark.skipif(not os.getenv('DB_URI'))
def test_some_feature(db):
# Use db fixture
...
Upvotes: 4
Views: 453
Reputation: 66241
Call pytest.skip
inside the fixture:
@pytest.fixture
def db():
db_uri = os.getenv('DB_URI', None)
if not db_uri:
pytest.skip('No database available')
else:
# Set up DB client and yield it
Upvotes: 7