vendredi 14 septembre 2018

Skip test from inside a fixture

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
  ...

Aucun commentaire:

Enregistrer un commentaire