假设我有一个需要实时数据库的装置。
如果实时数据库不存在,我想跳过依赖于该 fixture 的测试。
目前,我必须手动标记要跳过的测试,这感觉很多余:
@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
...
最佳答案
调用pytest.skip
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
关于python - 从 fixture 内部跳过测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52330369/