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

755
Views
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 answers
Answer question

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 Report

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 Report

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