Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
pytest: cómo habilitar explícitamente un complemento en la línea de comandos

Digamos que deshabilité un complemento de pytest en mi archivo pytest.ini como:

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

Ahora me gustaría poder habilitarlo a veces con argumentos de línea de comando, algo como:

 pytest -p yes:myplugin

¿Es eso posible? Por favor, si tiene mejores recomendaciones, me gustaría saber eso también.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Para volver a cargar el complemento, use -p pytest_myplugin . Esto funcionará cuando se encadene después de -p no:myplugin (ya sea en la línea de comandos o desde addopts de pytest.ini).

Qué está pasando aquí: cuando especifica -p no:plugin , pytest antepone "pytest_" a "plugin" . Esto se debe a que myplugin en realidad se importa desde pytest_myplugin . Desafortunadamente, esta conveniencia no se refleja en el lado de carga, que requiere el nombre completo del módulo del complemento.

over 4 years ago · Santiago Trujillo Report

0

Nunca he necesitado hacer esto, ya que es más fácil deshabilitar complementos a través de indicadores de línea de comandos. Como solución, puede especificar un archivo ini diferente usando la opción -c y tener un archivo ini diferente o incluso usar /dev/null como tengo a continuación

 $ 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

Si realmente lo necesitas, podrías hacer algo como. py.test -c <(grep -v no:django pytest.ini) usando un namedpipe de Unix y use grep o sed para eliminar la línea del complemento. Pero aún parece más fácil tener todos los complementos de forma predeterminada y deshabilitarlos a través de la línea de comandos.

 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

Alternativamente, no especificaría addopts= -p no:myplugin en pytest.ini y, en su lugar, usaría la variable de entorno PYTEST_ADDOPTS cuando quisiera desactivarlos. Pero esto es un ligero reverso de lo que pediste.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!