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
...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With