我的代码
@pytest.mark.parametrize(
("username", "password", "message"),
(
("", "", b"Username is required."),
("a", "", b"Password is required."),
("test", "test", b"already registered"),
),
)
def test_register_validate_input(client, username, password, message):
response = client.post(
"/register", data={"username": username, "password": password}
)
assert message in response.data
def test_register_delete_input(client, username, password, message):
response = client.delete(
"/register", data={"username": username, "password": password}
)
assert message in response.data
如果我运行python -m pytest,我得到
fixture 'username' not found
但是如果我移除
的blockdef test_register_delete_input(client, username, password, message):
response = client.delete(
"/register", data={"username": username, "password": password}
)
assert message in response.data
test works
- 我如何在删除测试中使用夹具?
- 在两个测试中只有post/delete的区别。有没有一种结合的方法?
-
您可以将
@pytest.mark.parametrize(...)
块从第一个测试复制粘贴到第二个测试,因为它只参数化了第一个测试,而不是第二个测试。或者,按照该用户的建议进行操作——从参数化的fixture中获取多个测试 -
理论上可以结合;但是,由于您正在测试两个不同的动作(第一个
post
和第二个delete
),我想说最好将这两个测试分开。