【问题标题】:Pytest hooks flowPytest 钩子流
【发布时间】:2019-02-14 20:51:40
【问题描述】:

我是 pytest 的新手,找不到我的问题的解决方案。

我知道一些 pytest 的钩子,例如 pytest_addoption()pytest_configure()

我试图弄清楚 pytest_addoption() 是否以及如何先运行,然后才运行 pytest_configure().

如果有人知道我在哪里可以找到一些信息或可以分享他的知识。 谢谢!

【问题讨论】:

  • 我会说这是不可能的; pytestpytest_configure 之前调用 pytest_addoption 挂钩,您对此无能为力。 Monkeypatching Config 类不是一个选项,因为它会破坏 pytest 内部。你为什么要这样做呢?用minimal reproducible example 描述您的问题,也许有一种方法可以在不重新排序钩子的情况下解决它。
  • @hoefling 我没有问如何改变这种行为。我正在寻找对 pytest 流程的解释,以了解它如何实现这些函数的优先级。我想确保 pytes_addoptionpytest_configure 之前钩子真的发生了我可以依靠这里的东西吗?在文档中找不到任何内容。

标签: pytest


【解决方案1】:

pytest中的钩子的流程在这里指定:

https://pytest.readthedocs.io/en/2.8.7/_modules/_pytest/hookspec.html

查看下面文档字符串中的第一行

def pytest_configure(config):
    """ called after command line options have been parsed
    and all plugins and initial conftest files been loaded.
    This hook is called for every plugin.
    """

【讨论】:

    猜你喜欢
    • 2017-04-01
    • 2022-11-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多