gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:53:17 30 4
gpt4 key购买 nike

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

我使用 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 标记的定义?

谢谢你。

最佳答案

一个不错的解决方案 from the documentation这是:

import pytest

@pytest.mark.parametrize(
("n", "expected"),
[
(1, 2),
pytest.param(1, 0, marks=pytest.mark.xfail),
pytest.param(1, 3, marks=pytest.mark.xfail(reason="some bug")),
(2, 3),
(3, 4),
(4, 5),
pytest.param(
10, 11, marks=pytest.mark.skipif(sys.version_info >= (3, 0), reason="py2k")
),
],
)
def test_increment(n, expected):
assert n + 1 == expected

关于pytest - 如何有条件地跳过参数化的 pytest 场景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47893861/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com