pytest如何在测试之间共享全局变量?

注意:pytest_namespace 现在已弃用

pytest 提供了一种在会话中使用一些全局变量的方法。这些变量也可以被 fixtures 使用。

这些变量是通过 pytest 挂钩控制的。

import pytest

def pytest_namespace():
    return {'my_global_variable': 0}

@pytest.fixture
def data():
    pytest.my_global_variable = 100

def test(data):
    print pytest.my_global_variable

 



posted on 2023-11-27 14:56  wmlg  阅读(258)  评论(0)    收藏  举报

导航