New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude variable from showlocals output #8974
Comments
This would be less annoying if there was a way to override |
Not sure I follow, can you elaborate on that? |
One way to customize tracebacks currently is Here it seems this should follow the same rationale of using a local variable to customize this behavior, because the customization is usually closely attached to the locals in the frame. One idea that comes to mind is create a new special variable to customize traceback rendering: __traceback_options__ = pytest.TracebackOptions(hide=True, hide_locals=["large_dict"]) This would then eventually replace |
I would like to keep showlocals on by default (via |
Filters for the locals should be a hook Also we should ensure its not dependent on the traceback objects we copied from pylib |
Not sure, often I have a bunch of utility code which I know will be used for testing and want to exclude frames containing implementation details. I wouldn't like to implement a hook for that. EDIT: unless you mean to have hooks in addition to some form of local customization, in which case I think it would be fine. |
This just bit me on pytest 7.1.2. I can't override the default Since this issue is very broadly scoped (hiding individual variables are a possibility), I created #10381 |
What'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.
The text was updated successfully, but these errors were encountered: