Exclude variable from showlocals output
See original GitHub issueWhat’s the problem this feature will solve?
I have a test which uses a large dictionary of words. With showlocals on (which is generally really useful and I have it globally enabled) this huge dictionary gets printed for any test failure.
This is distinct from the case of credentials, as my data is not private and I don’t care if something prints it, I just don’t want --showlocals to print it.
Describe the solution you’d like
A way of excluding variables from output, attached to either the test function via annotation, or a @pytest.fixture (in my case the dictionary is a fixture)
There must be other cases where large test data objects make the test output more difficult to read.
Alternative Solutions
Can disable showlocals and go back to normal debugging.
Can wrap the object in a class with a custom __repr__ and __str__ implementation. However this is clumsy, has too wide a scope, and is error prone (for example not implementing __eq__ may lead to test failures for string-like objects).
Additional context
I’m mostly looking for workarounds, I understand this is a niche request and might not be productive to be added into pytest itself.
Issue Analytics
- State:
 - Created 2 years ago
 - Comments:7 (5 by maintainers)
 

Top Related StackOverflow Question
I would like to keep showlocals on by default (via
addoptsinpytest.ini) but if the output is too noisy, disable it for particular invocations. Afaict there is no way to override the setting once it’s set.This just bit me on pytest 7.1.2. I can’t override the default
addopts. It feels like a bug.Since this issue is very broadly scoped (hiding individual variables are a possibility), I created https://github.com/pytest-dev/pytest/issues/10381