gpt4 book ai didi

python - 如何在 py.test 中加载自定义插件

转载 作者:太空宇宙 更新时间:2023-11-04 06:02:20 25 4
gpt4 key购买 nike

我在编写一个自定义插件时遇到问题,该插件用于在 rst 格式的文件中收集 py.test 结果。最后,我想将此文件包含到 Sphinx 文档中。

我已经在当前工作目录中的 myplugin.py 模块中编写了我的插件。然后我调用

py.test -p myplugin ../mytool/test

ImportError: No module named myplugin 结尾。

我也试过这样调用它

py.test -p .myplugin ../mytool/test

类似于相对导入,但没有成功。

如何正确使用插件?

Docs提供以下有关插件检测的信息:

Plugin discovery order at tool startup pytest loads plugin modules at tool startup in the following way:

  • by loading all builtin plugins

  • by loading all plugins registered through setuptools entry points.

  • by pre-scanning the command line for the -p name option and loading the specified plugin before actual command line parsing.

  • by loading all conftest.py files as inferred by the command line invocation:

if no test paths are specified use current dir as a test path if exists, load conftest.py and test*/conftest.py relative to the directory part of the first test path. Note that pytest does not find conftest.py files in deeper nested sub directories at tool startup. It is usually a good idea to keep your conftest.py file in the top level test or project root directory.

  • by recursively loading all plugins specified by the pytest_plugins variable in conftest.py files

最佳答案

如果插件不可导入,那是因为它不在 sys.path 上。尝试使用 PYTHONPATH 变量显式添加它:

PYTHONPATH=/path/to/dir/of/myplugin py.test -p myplugin ../mytool/test

关于python - 如何在 py.test 中加载自定义插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24166677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com