假设我有一个需要实时数据库的夹具.
如果实时数据库不存在,我想跳过依赖于该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
原文地址:https://codeday.me/bug/20190731/1586583.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。