2013-04-05 61 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