Closed vikramsubramanian closed 2 months ago
Hey
Sorry, despite the code snippet you shared, I'm unable to reproduce your issue. Do you have the possibility to share a more complete example to reproduce the error, with possibly the list of dependencies and their versions?
However I note the following:
.warning()
is very different from warnings.warn()
and the logs emitted won't be captured by warning handlers possibly installed by pytest
. You may need to re-call manually warnings.warn()
at the same time you log the warning.warnings.showwarning()
is not overloaded inside any test_x()
function. I tried to display warnings.showwarning.__code__.co_filename
from inside a testing function ran by pytest
, and it was the built-in Python showwarning()
instead of the replacement. It works fine if function is overloaded thanks to a fixture, though.sorry for making this topic stale so quickly. Things have been busy at work but I'll revisit this next week.
I will close this for now as I don't have time to investigate this. Sorry for the noise. I will try to revisit this as I have an internal issue about it in my org.
Hi again !
I'm moving a unittest-based test suite to pytest. We're using loguru together with a warning handler, something like this (only to show minimal reproducible code):
When I run pytest locally (
pytest -rxXsw
), and without the warning handler I see this:But as soon as I enable the warning handler (
warnings.showwarning = warning_handler
), the output looks like this when running pytest:Do you see what could possibly be going on here, and why the captured warning, re-logged via loguru, was not enough for pytest to show it in the warnings summary?
hashtaghashtaghashtag Side notes
The reason for doing this warning handling is I'm using Datadog and want to log everything to JSON format. Third-party libraries which are raising DeprecationWarnings must therefore be captured, so I can reformat them and set the desired severity level. I also use the
InterceptHandler
from the README.md, but for some reason the interceptor did not capture DeprecationWarnings from e.g. [redis]( but it worked as soon as I added this warning handler.For local execution, I'm not using Datadog and I do not format the loguru logs (I'm using the default formatting).