Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 499
jns Avatar asked Oct 27 '25 01:10

jns


1 Answers

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.

like image 170
jns Avatar answered Oct 28 '25 15:10

jns