【发布时间】:2016-05-12 09:35:27
【问题描述】:
我正在尝试重复运行一个参数化的测试。执行测试时似乎没有遵循顺序。我尝试使用 pytest-repeat 和 pytest.mark.parametrize 但我仍然没有得到想要的结果。 代码是
conftest.py
scenarios = [('first', {'attribute': 'value'}), ('second', {'attribute': 'value'})]
id = [scenario[0] for scenario in scenarios]
@pytest.fixture(scope="function", params=scenarios, ids=id)
def **get_scenario**(request):
return request.param
test_param.py
@pytest.mark.parametrize("count",range(3))
def test_scenarios(get_scenario,count):
assert get_scenario
当我执行时
py.test test_param.py
我得到的结果是
test_scenarios[first-0]
test_scenarios[first-1]
test_scenarios[first-2]
test_scenarios[second-0]
test_scenarios[second-1]
test_scenarios[second-2]
我预期的结果是
test_scenarios[first-0]
test_scenarios[second-0]
test_scenarios[first-1]
test_scenarios[second-1]
test_scenarios[first-2]
test_scenarios[second-2]
有什么方法可以让它像测试 "first" 设置日期和 "second" 取消设置数据一样工作,因此我需要维护订购,以便我可以运行重复测试。这些测试主要用于性能分析,测量通过 API 设置数据和清除数据的时间。非常感谢任何帮助。提前致谢
【问题讨论】: