【问题标题】:py.test fixture how can I change fixture's scopepytest 夹具如何更改夹具范围
【发布时间】:2016-07-18 07:13:17
【问题描述】:

我在两种模式下运行测试:使用裸 pytest 和使用 pytest-xdist。 我有一个用模块范围定义的重型夹具。在这个夹具中,我对使用 xdist 运行测试时的情况进行了一些优化:

@pytest.fixture(scope="module")
def myfixture(request):

    if running_with_pytest:
        pass
    else:
        pass

它工作正常,但我也想将夹具的范围更改为session(如果我使用 xdist 运行测试)。

我该怎么做?

【问题讨论】:

  • 您好,您是否找到了解决此问题的方法。我也面临同样的问题

标签: python pytest xdist


【解决方案1】:

我对命令行选项进行了很好的尝试,但似乎夹具参数scope 只接受字符串值,不能采用可调用函数: https://github.com/pytest-dev/pytest/issues/1682

我想只需要等到问题解决。 但是,如果您解决了这个问题,请分享您的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-16
    • 2022-06-12
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2022-01-21
    相关资源
    最近更新 更多