问题描述
所以我有以下结构:
class Test(object):
def test_1(self):
pass
def test_2(self):
pass
def test_3(self):
pass
它运行良好,现在我正在添加场景"(正如 pytest - testscenarios"的快速移植):
it runs great, NOW I'm adding the "scenarios" (as it's recommended at pytest - A quick port of "testscenarios"):
def pytest_generate_tests(metafunc):
idlist = []
argvalues = []
for scenario in metafunc.cls.scenarios:
idlist.append(scenario[0])
items = scenario[1].items()
argnames = [x[0] for x in items]
argvalues.append(([x[1] for x in items]))
metafunc.parametrize(argnames, argvalues, ids=idlist)
class Test(object):
scenarios = ['1' {'arg':'value1'},
'2' {'arg':'value2'}]
def test_1(self, arg):
pass
def test_2(self, arg):
pass
def test_3(self, arg):
pass
当我运行它时测试顺序错误,我得到:
When I run it the ORDER of tests is wrong, I get:
test_1[1]
test_1[2]
test_2[1]
test_2[2]
test_3[1]
test_3[2]
看起来不像是 Test 类的场景.
Doesn't really look like a scenario for the Test class.
问题:是否有以正确顺序运行它的解决方案?喜欢:
QUESTION: Is the any solution to run it in the correct order? like:
test_1[1]
test_2[1]
test_3[1]
test_1[2]
test_2[2]
test_3[2]
推荐答案
即将推出的 pytest-2.3 支持更好的(基于资源的)排序,我刚刚更新了文档中的场景示例:https://docs.pytest.org/en/latest/示例/parametrize.html#a-quick-port-of-testscenarios
The upcoming pytest-2.3 has support for better (resource-based) ordering, and i just updated the scenario example in the docs: https://docs.pytest.org/en/latest/example/parametrize.html#a-quick-port-of-testscenarios
您可以使用
pip install -i http://pypi.testrun.org -U pytest
并且应该使用py.test --version"获取 pytest-2.3.0.dev15 并能够使用它.
and should get pytest-2.3.0.dev15 with "py.test --version" and be able to use it.
这篇关于pytest 在课堂中以正确的顺序运行场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!