pytest - Pytest 会话夹具不再执行
问题描述
有一段时间,我在最高级别的 conftest.py 中运行了一个带有以下固定装置的测试套件。此文件包含必须可用于测试套件中的每个测试的固定装置。他们正在互相建设。一个夹具需要另一个。因此,执行顺序是隐含明确的。夹具基本上产生连接所需的对象。
@pytest.fixture(scope="session")
def A():
yield A
@pytest.fixture(scope="session")
def B(A):
yield B
@pytest.fixture(scope="session")
def C(B):
然后在某一时刻,设置不再起作用。只执行了第一个夹具。
@pytest.fixture(scope="session")
def A():
yield A
我们目前正在尝试检查可能已更改的确切内容,从而改变了行为。我们尝试更改 pytest 版本,更改 pytest.ini 文件或init .py 文件。到目前为止,我们还没有找到改变行为的任何原因。
有人有提示吗?
解决方案
添加autouse=True
参数使固定装置再次工作。
@pytest.fixture(scope="session", autouse=True)
def A():
yield A
@pytest.fixture(scope="session", autouse=True)
def B(A):
yield B
@pytest.fixture(scope="session", autouse=True)
def C(B):
推荐阅读
- sql - Left Join And vs Where on Second Table
- flask - gunicorn 烧瓶服务器为现有端点返回 404
- c# - C# 程序陷入 void 方法
- c - 制作 intptr_t 和 uintptr_t 可选类型的基本原理是什么?
- javascript - 用于搜索输入文本并从下拉列表中选择的书签
- android - 如何在 Android API 30 中隐藏系统 UI
- swiftui - 如何更改 Lazy Grid GridItem 的固定大小以响应动态文本大小更改?
- python - 如何在模块中声明变量的名称?
- c++ - Boost 库子目录中的文件不加载 (C++)
- typescript - 如何在泛型函数中引用“typeof T”?