Skip to content

Unwieldy inline display of helper function's parameters #5675

@vanschelven

Description

@vanschelven

pytest has specific support for reporting on failing assertions inside helper functions. See e.g. the following example from the documentation:

____________________ TestFailing.test_simple_multiline _____________________

self = <failure_demo.TestFailing object at 0xdeadbeef>

    def test_simple_multiline(self):
>       otherfunc_multi(42, 6 * 9)

failure_demo.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

a = 42, b = 54

    def otherfunc_multi(a, b):
>       assert a == b
E       assert 42 == 54

failure_demo.py:15: AssertionError

Of relevance to this issue is the fact that the values of the parameters to the helper function (a = 42, b = 54) are displayed here.

There are (at least) 2 problems with this:

  • When the __repr__ of these parameters is long (e.g. a full dataframe), this makes reading the formatted exception very hard to read. The particular situation in which this is annoying, is when the parameters of the helper function are large, but the helper function tests only a small aspect of this larger parameter. In this situation an assertion without the helper function would have displayed just fine; but extracting some logic to a helper function, i.e. practicing DRY, makes the stacktrace blow up.

  • When showlocals=True, the parameters are each displayed twice (once as a local, and once as per the default behavior)

There seems to be no way to turn this behavior off, while preserving the rest of the tb=auto behavior.

(The above behavior is for pytest 4.2.1; I did not check other versions, but the documentation does not seem to suggest the problem has been solved recently)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions