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.

Any way to respect pytest caplog level?

See original GitHub issue

pytest’s caplog allows the setting of level eg. caplog.set_level(logging.WARNING). Is there any way to set up the pytest fixture described here to respect whatever level it is set to?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Delgancommented, Apr 5, 2022

@mcarans Looks great. I didn’t realize we could access handler.level which is much better indeed.

I would just advise to use level=0 while adding the handler otherwise users won’t be able to test "TRACE" level for example.

I’ll update the documentation as well, thanks for the improvement suggestion. 👍

0reactions
Delgancommented, Apr 23, 2022

Thanks, I updated the recipe in Loguru documentation as well. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to manage logging — pytest documentation
By default the level is set on the root logger, however as a convenience it is also possible to set the log level...
Read more >
caplog.set_level() doesn't override log_level #7133 - GitHub
A "global" log level set by log_level cannot be overridden at the test level. Minimal Example: # setup.cfg [tool:pytest] log_level = CRITICAL ...
Read more >
Is there a way for pytest to check if a log entry was made at ...
here's some sample code from the docs which does some assertions based on the levels: def test_baz(caplog): func_under_test() for record in ...
Read more >
pytest Documentation - Read the Docs
pytest --show-capture=no. 2.10.1 caplog fixture. Inside tests it is possible to change the log level for the captured log messages.
Read more >
Reference — pytest documentation
One way to deal with this problem is to assert that two floating-point numbers are equal to within some appropriate tolerance:.
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