2013-04-05 58 views
2

我們有一個明顯的測試,我們預計不會執行,因爲py.test被另一個標記調用,但測試正在執行。pytest不跳過未標記的測試

例如

@pytest.mark.stress 
def test_one(some_fixture): 
    pass 

@pytest.mark.myplatform 
def test_two(some_fixture): 
    pass 

如果我運行--collectonly -m "myplatform and (not stress)「pytest作爲一個實驗,我知道我可以解決這個問題。我假設使用夾具以某種方式改變標誌進行評估的方式,但我們認爲在使用燈具不會影響測試收集與標記的方式。有一個在燈具看標記代碼,但我們不以任何方式改變pytest ARGS。 克里斯

+1

我無法重現此問題。 '-m'選項正確地爲你收集每個測試的代碼和一個空的'some_fixture'。我正在使用Python 2.7.5和pytest-2.5.2。你有更多的信息嗎? – 2014-03-25 00:53:06

+0

@ user2249625請嘗試我的答案http://stackoverflow.com/a/37583262/4988742讓我知道,如果這對你有效。 – 2016-06-05 00:04:24

回答

0

marker based test selection/unselection用於將測試運行限制爲明確標記的測試。如果您使用--collectonly選項(在以下示例中始終爲collected 3 items),您只是無法識別它。

考慮測試文件test_markers.py

import pytest 

@pytest.mark.stress 
def test_stress(): 
    pass 

@pytest.mark.myplatform 
def test_myplatform(): 
    pass 

def test_unmarked(): 
    pass 

如果你想要執行的 「壓力」 測試只使用(-v詳細輸出)

pytest test_markers.py -v -m stress 

將得到以下的輸出:

collected 3 items 

test_markers.py::test_stress PASSED 

如果你想執行「壓力」tes TS和無人盯防的測試使用:

pytest test_markers.py -v -m "not myplatform" 

它爲您提供了輸出:

collected 3 items 

test_markers.py::test_stress PASSED 
test_markers.py::test_unmarked PASSED