小编Eyt*_*Gro的帖子

在 pytest 中使用双参数化将测试标记为 xfail

我有一个 pytest 测试,可以针对两个不同的数据库测试多个输入。我使用参数化标记两次来做到这一点:

@pytest.mark.parametrize(
    "input_type",
    [
        pytest.param("input_1"),
        pytest.param("input_2"),
    ],
)
@pytest.mark.parametrize(
    "db_type",
    [
        pytest.param("db_type_1"),
        pytest.param("db_type_2"),
    ],
)
Run Code Online (Sandbox Code Playgroud)

我所经历的只是当运行input_1db_type_2例如)测试由于错误而失败但使用不同的数据库传递运行相同的输入时。input_1我只想将和组合标记db_type_2为 xfail,而所有其他组合不应标记为 xfail。我找不到如何做到这一点。

如果标记db_type_2为 xfail:

@pytest.mark.parametrize(
    "db_type",
    [
        pytest.param("db_type_1"),
        pytest.param("db_type_2", marks=pytest.mark.xfail)
    ],
)
Run Code Online (Sandbox Code Playgroud)

所有输入都将失败,这不是我正在寻找的行为。有人可以帮我解决这个问题吗?

python pytest parametrized-testing

4
推荐指数
1
解决办法
775
查看次数

标签 统计

parametrized-testing ×1

pytest ×1

python ×1