即使文件中有兩個類,我們也會看到此問題,並且我們已經爲這兩個類中的函數定義了順序。
例子:
class Test_abc:
@pytest.mark.run(order=1)
def test_func_a(self):
print 'class 1 test 1'
@pytest.mark.run(order=1)
def test_func_b(self):
print 'class 1 test 2'
@pytest.mark.run(order=1)
def test_func_c(self):
print 'class 1 test 3'
class Test_bcd:
@pytest.mark.run(order=1)
def test_func_ab(self):
print 'class 2 test 1'
@pytest.mark.run(order=1)
def test_func_bc(self):
print 'class 2 test 2'
@pytest.mark.run(order=1)
def test_func_cd(self):
print 'class 2 test 3'
輸出是這樣的:
class 1 test 1
class 2 test 1
class 1 test 2
class 2 test 1
class 1 test 3
class 2 test 1
我做了這樣的事情來解決這個問題
@pytest.mark.run(order=1)
class Test_abc:
def test_func_a(self):
print 'class 1 test 1'
def test_func_b(self):
print 'class 1 test 2'
def test_func_c(self):
print 'class 1 test 3'
@pytest.mark.run(order=2)
class Test_bcd:
def test_func_ab(self):
print 'class 2 test 1'
def test_func_bc(self):
print 'class 2 test 2'
def test_func_cd(self):
print 'class 2 test 3'
輸出:
class 1 test 1
class 1 test 2
class 1 test 3
class 2 test 1
class 2 test 2
class 2 test 3
所以,就你的問題,我認爲你可以嘗試這樣的事情。我知道這不是你的問題的完美答案,但你可以即興使用這個解決方案。 我試着用文件(和文件名)做這個。 pytest編譯器似乎被編程爲按順序編號或字母。因此,您可能需要將文件命名爲test_1_foo.py
和test_2_bar.py
或test_a.py
和test_b.py
以按順序執行它們。 但我個人覺得第一種方式更好。
每個測試文件中的代碼是否相同?你使用了什麼命令,並且可以包含該命令的輸出? –
測試用例名稱differer我確保沒有重複的測試用例方法名稱,只是在測試用例文件中有重複的順序號。我運行命令「py.test test_ * -vv」 –