I'm trying out pytest
for the first time. How do I suppress warnings issued about other peoples code that my code depends on without suppressing warnings about my own code?
Right now I have this in my pytest.ini
so I don't have to see pytest warn me about some deprecation on the jsonschema
package that I'm using.
[pytest]
filterwarnings =
ignore::DeprecationWarning
But now if I write anything in my own code that should fire of a deprecation warning I'll miss it.
Disabling warnings summary Although not recommended, you can use the --disable-warnings command-line option to suppress the warning summary entirely from the test run output.
All warnings are ignored by setting the first parameter of warnings. simplefilter() , action , to 'ignore' . See the official documentation for the warning filters you can set for action .
-r chars show extra test summary info as specified by chars (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings (a)all. This will allow to show warnings in the report (top portion of the record) will list which pytest plugins use deprecated arguments (in my case bellow):
DeprecationWarning errors are logged by the Node. js runtime when your code (or one of the dependencies in your code) calls a deprecated API. These warnings usually include a DEP deprecation code. They are logged using console.
The syntax for pytest-warning is action:message:category:module:lineno
. You can use this config for ignoring only jsonschema:
[pytest]
filterwarnings =
ignore::DeprecationWarning:jsonschema
You can also use regex in those fields. If you want to exclude all warnings except yours:
[pytest]
filterwarnings =
ignore::DeprecationWarning:!yourtestmodule
Pytest uses the same filterwarning as python. You can learn more about python warnings here: https://docs.python.org/3/library/warnings.html#warning-filter
Source: https://github.com/fschulze/pytest-warnings/blob/master/pytest_warnings/init.py#L18
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With