2016-03-10 118 views
0

嗨,我使用「http://pytest-ordering.readthedocs.org/en/develop/」,當我使用的裝飾如下順序工作正常上班,pytest下令插件不具有的多個文件組合

import pytest 

@pytest.mark.run(order=3) 
def test_three(): 
    assert True 

@pytest.mark.run(order=1) 
def test_four(): 
    assert True 

@pytest.mark.run(order=2) 
def test_two(): 
    assert True 

現在說我有兩個文件test_example1.py和第二個文件test_example2.py

在這種情況下,如果我用這個順序再下訂單= 1,從文件1和文件2被執行,然後再它開始在這兩個文件

執行順序= 2有沒有什麼辦法指定僅在fil中說明訂單檢查目前正在執行的?

+0

每個測試文件中的代碼是否相同?你使用了什麼命令,並且可以包含該命令的輸出? –

+0

測試用例名稱differer我確保沒有重複的測試用例方法名稱,只是在測試用例文件中有重複的順序號。我運行命令「py.test test_ * -vv」 –

回答

0

即使文件中有兩個類,我們也會看到此問題,並且我們已經爲這兩個類中的函數定義了順序。

例子:

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.pytest_2_bar.pytest_a.pytest_b.py以按順序執行它們。 但我個人覺得第一種方式更好。