python – 从夹具内部跳过测试
发布时间:2020-12-20 11:07:19 所属栏目:Python 来源:网络整理
导读:假设我有一个需要实时数据库的夹具. 如果实时数据库不存在,我想跳过依赖于该fixture的测试. 目前,我必须手动标记要跳过的测试,这感觉多余: @pytest.fixturedef db_client(): DB_URI = os.getenv('DB_URI') # Set up DB client and yield it@pytest.mark.ski
|
假设我有一个需要实时数据库的夹具.
如果实时数据库不存在,我想跳过依赖于该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:
@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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
