Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
pytest: how to explicitly enable a plugin in command line

Let's say I disabled a pytest plugin in my pytest.ini file like:

[pytest]
...
addopts=
    -p no:myplugin

Now I would like to be able to enable it sometimes with command line arguments, something like:

pytest -p yes:myplugin

Is that possible? Please, if you have better recommendations, I would like to know that too.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

To load the plugin again, use -p pytest_myplugin. This will work when chained after -p no:myplugin (either on the command-line, or from pytest.ini's addopts).

What's happening here: when you specify -p no:plugin, pytest prepends "pytest_" to "plugin". This is because myplugin is actually imported from pytest_myplugin. Unfortunately, this convenience isn't mirrored on the loading side, which requires the full module name of the plugin.

over 4 years ago · Santiago Trujillo Denunciar

0

I haven't ever needed to do this, as it is easier to disable plugins via commandline flags. As a workaround you can either specify a different ini file using the -c option and either have a different ini file or even use /dev/null as I have below

$ cat pytest.ini
[pytest]
addopts= -p no:django
$ py.test 
================================================= test session starts 
platform linux -- Python 3.4.3, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/me/python, inifile: pytest.ini
plugins: pep8-1.0.6, cov-2.4.0
collected 0 items 
============================================ no tests ran in 0.02 seconds    
$ py.test -c /dev/null
================================================= test session starts
platform linux -- Python 3.4.3, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/me/python, inifile: /dev/null
plugins: django-3.1.2, pep8-1.0.6, cov-2.4.0
collected 0 items 
============================================ no tests ran in 0.02 seconds

If you really need it, you could do something like. py.test -c <(grep -v no:django pytest.ini) using a unix namedpipe and use grep or sed to remove the plugin line. But it still seems easier to have all plugins by default and disable via commandline.

py.test -c <(grep -v no:django pytest.ini)
================================================= test session starts 
platform linux -- Python 3.4.3, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/me/python, inifile: /dev/fd/63
plugins: django-3.1.2, pep8-1.0.6, cov-2.4.0
collected 0 items 
============================================ no tests ran in 0.03 seconds

Alternatively I would not specify addopts= -p no:myplugin in pytest.ini and instead use the PYTEST_ADDOPTS environment variable when I wanted to switch them off. But this is a slight reverse of what you asked for

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda