我有一个由 POST 创建的资源,然后可以通过 PUT 进行更新。
如果有人调用 PUT 并且没有更改任何内容,它是否仍应返回 200 并且看起来已执行更新(即使实际上没有更新任何内容)?
我有一个使用夹具作为凭证的python测试(用户ID和密码的元组)
def test_something(credentials)
(userid, password) = credentials
print("Hello {0}, welcome to my test".format(userid))
Run Code Online (Sandbox Code Playgroud)
我有pytest夹具来获取凭据:
@pytest.fixture()
def credentials():
return ("my_userid", "my_password")
Run Code Online (Sandbox Code Playgroud)
效果很好
现在,我想将此扩展为多个凭证(例如,登台和生产),以便我的测试将运行两次(每个登台和生产一次)。
我以为参数化是答案,但似乎我无法使用灯具进行参数化。
我想做这样的事情:
@pytest.fixture(params=[staging_credentials, production_credentials])
def credentials(request):
return request.param
Run Code Online (Sandbox Code Playgroud)
其中staging_credentials和production_credentials都是固定装置:
@pytest.fixture()
def staging_credentials():
return ("staging_userid", "staging_password")
@pytest.fixture()
def production_credentials():
return ("prod_userid", "prod_password")
Run Code Online (Sandbox Code Playgroud)
但显然灯具的参数不能是其他灯具。
关于如何优雅地处理此问题的任何建议?我看过https://docs.pytest.org/zh-CN/latest/proposals/parametrize_with_fixtures.html,但这似乎是蛮力的。
谢谢!史蒂夫