Replies: 1 comment 2 replies
-
as showwarning is replaced by logging, the code works "as intended" but not "as expected/desired so in order to test/examine warnings as always shown, its necessary to use one of the warning module utilities to add a temporary additional filter to let things be |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to test a context manager that sets up logging for my application and redirects warnings to logging with
logging.captureWarnings(True)
. I want to assert that a warning is not raised, but is logged instead. Here is a minimal example:with default
filterwarnings
configuration, it works as expected. the warning is redirected to logging and not raised:with
filterwarnings=error
, the warning is raised, not logged, and the test fails. This is counterintuitive - it seems that pytest's configuration is affecting the behavior of the code under test:It seems that pytest's
filterwarnings
configuration is implemented using thewarnings
filter, which overrideslogging.captureWarnings
and affects the code being tested. Is it possible to test the functionality oflogging.captureWarnings
with pytest?Beta Was this translation helpful? Give feedback.
All reactions