小编Kei*_*lan的帖子

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

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

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

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

@pytest.mark.hermes_only
def test_blah_with_hermes(self):
Run Code Online (Sandbox Code Playgroud)

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

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

@pytest.mark.parametrize('prefix', outfile_scenarios)
def test_blah_build(self, prefix):
    self._activator(prefix=prefix)
Run Code Online (Sandbox Code Playgroud)

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

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

pytest

9
推荐指数
2
解决办法
8562
查看次数

标签 统计

pytest ×1