pythontestingpytest

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?


Solution

  • 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