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

745
Vistas
Show exhaustive information for passed tests in pytest

When a test fails, there's an output indicating the context of the test, e.g.

=================================== 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

What if I want the same thing for passed tests as well? so that I can have a quick check on the parameters that get passed to the tests are correct?

I tried command line options line --full-trace, -l, --tb long, and -rpP, but none of them works.

Any idea?

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

0

Executing pytest with the --verbose flag will cause it to list the fully qualified name of every test as it executes, e.g.,:

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 Denunciar

0

If you are just asking for standard output from passed test cases, then you need to pass the -s option to pytest to prevent capturing of standard output. More info about standard output suppression is available in the pytest docs.

over 4 years ago · Santiago Trujillo Denunciar

0

pytest doesn't have this functionality. What it does is showing you the error from the exception when an assertion fails.

A workaround is to explicitly include the information you want to see from the passing tests by using python's logging module and then use the caplog fixture from pytest.

For example one version of a func.py could be:

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 ...

and then a 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

If you run pytest -s test_even.py and since the test passes, the logger shows you the following message:

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

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