[英]Pytest. Test parametrization does not work
代码如下:
import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
assert x > y
但是通过运行测试系统给出:
进程以退出代码 0 结束
有人知道为什么它不起作用吗?
试试这个代码:
import pytest
@pytest.mark.parametrize(params=["x", [0, 1]])
def test_foo(x, y):
assert x > y
我已经运行了你的代码,它工作正常并且也给出了断言错误。
在这里,您似乎正在像普通的 python 文件一样运行测试。
您需要将文件作为 pytest 测试运行。 为此,您需要设置 pytest 配置。
在 pycharm、Go 中运行 -> 编辑配置... 然后单击模态对话框左上角的 +。 Select "python tests" -> py.test 然后我给它起一个名字,比如 "All test with py.test"
select 目标:模块名称或测试文件的路径 > 点击 OK
现在从运行菜单 select 运行“使用 py.test 进行所有测试”或按 shift+f10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.