Thursday, April 28, 2022

[FIXED] How to ignore all warnings except from one package in pytest?

Issue

When running pytest, I would like to ignore warnings from third-party packages. I know how to ignore one specific package (see https://stackoverflow.com/a/53218641/2057762), but how do I ignore all but one?


Solution

You need to set two filter rules:

[pytest]
filterwarnings =
    ignore
    default:::mypackage.*

You can apply multiple filters, so ignore everything and re-allow warnings for your package. The last one has highest precedence. Filter syntax is action:message:category:module:line. Possible actions and more details can be found in here.



Answered By - jns
Answer Checked By - Cary Denson (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.