Tengo pruebas dentro del mismo repository (archivos pytest.ini separados) que requieren diferentes complementos de pytest. ¿Cómo puedo deshabilitar varios complementos en pytest.ini sin desinstalarlos?
https://docs.pytest.org/en/latest/plugins.html#findpluginname
addopts = --nomigrations --reuse-db -s -p no:pytest-splinter
funciona bien, pero también quiero desactivar pytest-django y pytest-bdd para una de las suites de prueba. ¿Cómo puedo hacer eso? He intentado:
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
todos fallan, y la documentación no describe cómo se hace esto. Cualquier puntero muy apreciado, gracias!
El uso con el paso repetido de la opción -p
es el correcto. Sin embargo, está utilizando los nombres de complementos incorrectos. En lugar de pasar los nombres de paquetes PyPI, use los nombres de complementos pytest
:
addopts = --nomigrations --reuse-db -s -p no:pytest-splinter -p no:django
Cuando tenga dudas sobre si usar el nombre correcto del complemento, use pytest --trace-config
para enumerar todos los complementos instalados junto con sus nombres:
$ pytest --trace-config ... PLUGIN registered: PLUGIN registered: ... =============================================== 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 ...
pytest --trace-config
falla En ese caso, puede consultar los metadatos de los paquetes instalados directamente, por ejemplo, utilizando pkg_resources
(parte del paquete setuptools
, que está preinstalado en la mayoría de las distribuciones de Python en la actualidad; de lo contrario, instálelo como de costumbre: pip install --user setuptools
:
import os import pkg_resources data = ['{}-{}: {}'.format(dist.project_name, dist.version, ' '.join(dist.get_entry_map(group='pytest11').keys())) for dist in pkg_resources.working_set if dist.get_entry_map(group='pytest11')] print(os.linesep.join(data))
Ejemplo de salida:
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
Otra posibilidad de averiguar el nombre del complemento es buscar en el código fuente del complemento. El nombre está en la statement del punto de entrada del complemento:
entry_points={'pytest11': [ 'plugin_name=plugin.registration.module', ]}
Así,
pytest-splinter
es pytest-splinter
(duh!), pytest-django
es django
.