【发布时间】:2012-09-20 22:37:06
【问题描述】:
所以我有以下结构:
class Test(object):
def test_1(self):
pass
def test_2(self):
pass
def test_3(self):
pass
它运行得很好,现在我正在添加“场景”(正如 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
当我运行它时,测试顺序错误,我得到:
test_1[1]
test_1[2]
test_2[1]
test_2[2]
test_3[1]
test_3[2]
看起来不像是 Test 类的场景。
问题:是否有任何解决方案可以以正确的顺序运行它?喜欢:
test_1[1]
test_2[1]
test_3[1]
test_1[2]
test_2[2]
test_3[2]
【问题讨论】: