如何有条件地跳过参数化pytest场景?

问题描述 投票:2回答:1

我需要标记某些要跳过的测试。但是,有些测试是参数化的,我需要能够仅跳过某些场景。

我根据需要使用py.test -m "hermes_only"py.test -m "not hermes_only"调用测试。

简单测试用例使用以下标记:

@pytest.mark.hermes_only
def test_blah_with_hermes(self):

但是,我有一些参数化测试:

outfile_scenarios = [('buildHermes'),
                     ('buildTrinity')]

@pytest.mark.parametrize('prefix', outfile_scenarios)
def test_blah_build(self, prefix):
    self._activator(prefix=prefix)

我想要一种机制来过滤场景列表,或者如果定义了pytest标记,则跳过某些测试。

更一般地说,我如何测试pytest标记的定义?

谢谢。

pytest
1个回答
2
投票

找到了!它的简洁优雅。我只是标记受影响的场景:

outfile_scenarios = [pytest.mark.hermes_only('buildHermes'),
                     ('buildTrinity')]

我希望这有助于其他人。

© www.soinside.com 2019 - 2024. All rights reserved.