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

744
Views
Mostrar información exhaustiva para las pruebas aprobadas en pytest

Cuando una prueba falla, hay una salida que indica el contexto de la prueba, por ejemplo

 =================================== FAILURES =================================== ______________________________ Test.test_sum_even ______________________________ numbers = [2, 4, 6] @staticmethod def test_sum_even(numbers): assert sum(numbers) % 2 == 0 > assert False E assert False test_preprocessing.py:52: AssertionError

¿Qué pasa si también quiero lo mismo para las pruebas aprobadas? para que pueda tener una verificación rápida de los parámetros que se pasan a las pruebas son correctos?

Probé la línea de opciones de la línea de comandos --full-trace , -l , --tb long y -rpP , pero ninguna de ellas funciona.

¿Alguna idea?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Ejecutar pytest con el indicador --verbose hará que se enumere el nombre completo de cada prueba a medida que se ejecuta, por ejemplo:

 tests/dsl/test_ancestor.py::TestAncestor::test_finds_ancestor_nodes tests/dsl/test_and.py::TestAnd::test_aliased_as_ampersand tests/dsl/test_and.py::TestAnd::test_finds_all_nodes_in_both_expressions tests/dsl/test_anywhere.py::TestAnywhere::test_finds_all_nodes_when_no_arguments_given_regardless_of_the_context tests/dsl/test_anywhere.py::TestAnywhere::test_finds_multiple_kinds_of_nodes_regardless_of_the_context tests/dsl/test_anywhere.py::TestAnywhere::test_finds_nodes_regardless_of_the_context tests/dsl/test_axis.py::TestAxis::test_finds_nodes_given_the_xpath_axis tests/dsl/test_axis.py::TestAxis::test_finds_nodes_given_the_xpath_axis_without_a_specific_tag
over 4 years ago · Santiago Trujillo Report

0

Si solo está solicitando la salida estándar de los casos de prueba aprobados, entonces debe pasar la opción -s a pytest para evitar la captura de la salida estándar. Más información sobre la supresión de salida estándar está disponible en los documentos de pytest .

over 4 years ago · Santiago Trujillo Report

0

pytest no tiene esta funcionalidad. Lo que hace es mostrarle el error de la excepción cuando falla una aserción.

Una solución consiste en incluir explícitamente la información que desea ver de las pruebas aprobadas mediante el uso del módulo de registro de python y luego usar el accesorio caplog de pytest .

Por ejemplo, una versión de un func.py podría ser:

 import logging logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('my-even-logger') def is_even(numbers): res = sum(numbers) % 2 == 0 if res is True: log.warning('Sum is Even') else: log.warning('Sum is Odd') #... do stuff ...

y luego un test_func.py :

 import logging import pytest from func import is_even @pytest.fixture def my_list(): numbers = [2, 4, 6] return numbers def test_is_even(caplog, my_list): with caplog.at_level(logging.DEBUG, logger='my-even-logger'): is_even(my_list) assert 'Even' in caplog.text

Si ejecuta pytest -s test_even.py y dado que la prueba pasa, el registrador le muestra el siguiente mensaje:

test_even.py WARNING:my-sum-logger:Sum is Even

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!