【发布时间】:2019-10-16 08:50:23
【问题描述】:
我有一个 test-case 和一个 fixture:
@pytest.fixture
def user(test_client):
return User.objects.first()
@pytest.mark.parametrize('content', ['nice post',])
def test_post(test_client, user, content):
reponse = test_client.post(
'/api/v1.0/posts',
json={
'content': content,
'author': user,
},
follow_redirects=True
)
assert reponse.status_code == 200
但除了针对某些User 对象进行测试之外,我还想针对None 进行测试(我希望测试失败为无)。我想我可以这样做:
@pytest.fixture(params=[True, False])
def User_or_null(test_client, request):
if request.param:
return User.objects.first()
else:
return None
但我不认为这将允许我用pytest.mark.xfail 标记测试用例None 值?有什么想法吗?
【问题讨论】:
标签: python integration-testing pytest