@@ -214,6 +214,30 @@ Some examples::
214214 ignore,default:::mymodule # Only report warnings triggered by "mymodule"
215215 error:::mymodule # Convert warnings to errors in "mymodule"
216216
217+ .. _warning-filter-examples :
218+
219+ Warning Filter Examples
220+ ~~~~~~~~~~~~~~~~~~~~~~~
221+
222+ Here are some complex examples for filtering warnings.
223+
224+ Note that :func: `filterwarnings ` filters have subtle differences
225+ from :option: `-W ` and :envvar: `PYTHONWARNINGS ` regarding the *message * and *module *
226+ parts of the filter (as described in :ref: `warning-filter `).
227+
228+ filterwarnings("ignore", message=".*generic", module=r"yourmodule\. submodule")
229+ # Ignore warnings in "yourmodule.submodule" which contain "generic"
230+ filterwarnings("ignore", message="generic", module=r"yourmodule\. submodule")
231+ # Ignore warnings in "yourmodule.submodule" which START with "generic"
232+ filterwarnings("ignore", module="yourmodule.*")
233+ # Ignore all warnings in "yourmodule" and its submodules
234+
235+ -W "ignore:generic::yourmodule.submodule: "
236+ # Ignore warnings in "yourmodule.submodule" which START with "generic" (but not those containing it).
237+ # Also note that the '.' in the module does not need to be escaped since it is not a regex
238+ -W "ignore:::yourmodule: "
239+ # Ignore all warnings in "yourmodule", but NOT in its submodules
240+
217241
218242.. _default-warning-filter :
219243
0 commit comments