@pytest.mark.parametrize(“测试输入”,[1,2,3,4]) 类测试类: 定义test_something1(自我,测试输入): #这里的测试代码,每次为参数化运行
类测试类: 定义test_something1(自我): 对于我来说: #在此处测试代码 定义test_something2(自我): 对于我来说: #在此处测试代码 ...
@pytest.mark.parametrize(“测试输入”,[1,2,3,4]) 类测试类: 定义test_something1(自我,测试输入): #这里的测试代码,每次为参数化运行
类测试类: 定义test_something1(自我): 对于我来说: #在此处测试代码 定义test_something2(自我): 对于我来说: #在此处测试代码 ...
py.test测试
@pytest.mark.参数化 允许在测试函数或 班 .
@pytest.mark.parametrize(“测试输入”,[1,2,3,4]) 类测试类: 定义test_something1(自我,测试输入): 通过 定义test_something2(自我,测试输入): 通过
===============================================================================测试会话开始============================================================================================ 平台darwin--Python 3.7.3、pytest-4.4.2、py-1.8.0、pluggy-0.11.0--/Users/user/.local/share/virtualenvs/stack-overflow-pycharm-L-07rBZ9/bin/python3.7 缓存目录:.pytest_cache rootdir:/Users/user/Documents/spikes/stack-overlfow-pycharm 收集了8个项目 test_class.py::TestClass::test_something1[1]通过[12%] test_class.py::TestClass::test_something1[2]通过[25%] test_class.py::TestClass::test_something1[3]通过[37%] test_class.py::TestClass::test_something1[4]通过[50%] test_class.py::TestClass::test_something2[1]通过[62%] test_class.py::TestClass::test_something2[2]通过[75%] test_class.py::TestClass::test_something2[3]通过[87%] test_class.py::TestClass::test_something2[4]通过[100%] ====~========2===:===>===]===+===_====1===%====0.====3===<=======#===0===*===8秒通过0.03秒=========================================================================================
类测试类: 定义test_something(自我): 对于example_params中的i: 打印(i)
导入pytest example_params=[1,2,3] @pytest.fixture(params=example_params) def param_loop(请求): 返回请求.param 类测试类: 定义test_something(self,param_loop): 打印(param_loop)
@pytest.ffixture(参数=[])
定义my_function(请求)
我的函数(_F)
返回请求.param
我的函数(_F)
失败:不允许访问数据库,请使用“django_db”标记或“db”或“transactional_db”装置来启用它。
示例参数
参数_循环
pytest测试
参数化