pytest-dev / pytest-dev/pytest
Unwieldy inline display of helper function's parameters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reporting example linked in the issue and reproduce the helper-function traceback using pytest 4.2.1, comparing default output with showlocals=True and tb=auto. Trace the traceback-reporting entry point responsible for displaying helper parameters. Done means long parameter representations can be suppressed without losing the rest of tb=auto behavior or causing duplicate locals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100