python - pytest.mark.parametrize 中的 indirect = True/False 是什么意思?

标签 python pytest

我只是想了解它是什么意思,或者如果我在 pytest.mark.parametrize 中将间接参数设置为 True 或 False 会发生什么?

谢谢

最佳答案

使用 indirect=True 你可以参数化你的 fixture,False - 默认值。示例:

import pytest

@pytest.fixture
def fixture_name(request):
    return request.param

@pytest.mark.parametrize('fixture_name', ['foo', 'bar'], indirect=True)
def test_indirect(fixture_name):
    assert fixture_name == 'baz'

所以这个例子生成了两个测试。第一个来自 fixture_namefoo,因为此测试的 fixture 使用参数化运行。第二个测试得到 bar 值。由于对 baz 进行断言检查,因此每个测试都会失败。

关于python - pytest.mark.parametrize 中的 indirect = True/False 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35413134/

相关文章:

python - Django + Pytest + Selenium

python - 如何在不知道类型的情况下在 python 中捕获异常并获取对异常的引用?

python - If-Then-Else 正则表达式语句

python - BeautifulSoup,1 个元素有 2 个相同的链接,如何只打印 1 个?

python - 为什么 unittest.Test Cases 看不到我的 pytest fixtures?

python - 如何在 pytest 中使用具有不同数据结构的不同 fixture 进行一次测试?

django - 模型实例 fixture 未保留在数据库中

python - 如何在Python中执行断言自省(introspection)

python - 将一个元组复制到多个组中

python - 这个循环方法正确吗? Python 3.4.3