Python 如何在pytest.ini中禁用多个插件?

Python 如何在pytest.ini中禁用多个插件?,python,testing,pytest,Python,Testing,Pytest,我在同一个存储库(单独的pytest.ini文件)中有需要不同pytest插件的测试。如何在pytest.ini中禁用多个插件而不卸载它们 工作正常,但我还想为其中一个测试套件禁用pytest django和pytest bdd。我该怎么做?我试过: addopts = --nomigrations --reuse-db -s -p no:pytest-splinter -p no:pytest-django addopts = --nomigrations --reuse-db -s -

我在同一个存储库(单独的pytest.ini文件)中有需要不同pytest插件的测试。如何在pytest.ini中禁用多个插件而不卸载它们

工作正常,但我还想为其中一个测试套件禁用pytest django和pytest bdd。我该怎么做?我试过:

addopts = --nomigrations --reuse-db -s -p no:pytest-splinter -p no:pytest-django 

addopts = --nomigrations --reuse-db -s -p no:pytest-splinter no:pytest-django 

addopts = --nomigrations --reuse-db -s -p no:pytest-splinter pytest-django 

所有这些都失败了,文档中没有描述如何做到这一点。非常感谢您的指点,谢谢

重复传递
-p
选项的用法是正确的。但是,您使用了错误的插件名称。使用
pytest
插件名称,而不是传递PyPI包名称:

addopts = --nomigrations --reuse-db -s -p no:pytest-splinter -p no:django
如果怀疑是否使用了正确的插件名称,请使用
pytest--trace config
列出所有已安装的插件及其名称:

$ pytest --trace-config
...
PLUGIN registered: <module 'pytest_html.plugin' from '/Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_html/plugin.py'>
PLUGIN registered: <module 'pytest_django.plugin' from '/Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_django/plugin.py'>
...
=============================================== test session starts ===============================================
platform darwin -- Python 3.6.4, pytest-3.7.3.dev26+g7f6c2888, py-1.5.4, pluggy-0.7.1
using: pytest-3.7.3.dev26+g7f6c2888 pylib-1.5.4
setuptools registered plugins:
  pytest-metadata-1.7.0 at /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_metadata/plugin.py
  pytest-html-1.19.0 at /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_html/plugin.py
  pytest-django-3.4.2 at /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_django/plugin.py
active plugins:
    metadata : /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_metadata/plugin.py
    html     : /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_html/plugin.py
    django   : /Users/hoefling/.virtualenvs/stackoverflow/lib/python3.6/site-packages/pytest_django/plugin.py
...
示例输出:

requests-mock-1.5.2: requests_mock
pytest-splinter-1.9.1: pytest-splinter
pytest-metadata-1.7.0: metadata
pytest-html-1.19.0: html
pytest-django-3.4.2: django
查找插件名称的另一种可能性是查看插件的源代码。该名称位于插件的入口点声明中:

entry_points={'pytest11': [
    'plugin_name=plugin.registration.module',
]}
因此,

  • (duh!)

啊哈!谢谢@hoefling,我无法加载--trace-config,因为插件本身正在抛出异常(因此需要禁用它们)。哦,我明白了!这是一个更有趣的问题-当
pytest--trace config
首先失败时该怎么办,因为一些插件很早就出现了错误。然后可以直接查询已安装的包元数据;我用一个简单的助手脚本更新了答案,这真的很有用!感谢@hoefling提供的额外信息!!
requests-mock-1.5.2: requests_mock
pytest-splinter-1.9.1: pytest-splinter
pytest-metadata-1.7.0: metadata
pytest-html-1.19.0: html
pytest-django-3.4.2: django
entry_points={'pytest11': [
    'plugin_name=plugin.registration.module',
]}