question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exclude variable from showlocals output

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
richardjharriscommented, Aug 6, 2021

This would be less annoying if there was a way to override --showlocals e.g. --showlocals=false to disable the global configuration.

Not sure I follow, can you elaborate on that?

I would like to keep showlocals on by default (via addopts in pytest.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.

0reactions
tonycommented, Oct 13, 2022

This would be less annoying if there was a way to override --showlocals e.g. --showlocals=false

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to exclude variables (columns) from an R - Stack Overflow
Now I want to remove those which are not significant, here in this case "MaritalStatusMarried" is not significant. MaritalStatus is a variable( ...
Read more >
pytest cheat sheet - gists · GitHub
... (P)passed with output, (a)all except pP. -v Verbose -q, --quiet Less verbose -l, --showlocals Show local variables in tracebacks ...
Read more >
Solved: proc sql how to exclude variables from being selected
Solved: Hi, I am creating a table using proc sql and was wondering if someone could help me to select all of the...
Read more >
Usage and Invocations — pytest documentation
pytest --showlocals # show local variables in tracebacks pytest -l # show ... By default no output will be shown (because KeyboardInterrupt is...
Read more >
The command line interface - pytask - Read the Docs
Collect tasks, execute them and report the results. This is pytask's default command. pytask collects tasks from the given paths or the current...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found