diff --git a/doc/en/how-to/capture-warnings.rst b/doc/en/how-to/capture-warnings.rst index 8ed546bedf7..2bf42adc0f7 100644 --- a/doc/en/how-to/capture-warnings.rst +++ b/doc/en/how-to/capture-warnings.rst @@ -91,9 +91,9 @@ all other warnings into errors. [pytest] filterwarnings = [ - "error", - "ignore::UserWarning", - # note the use of single quote below to denote "raw" strings in TOML + 'error', + 'ignore::UserWarning', + # Note the use of single quote below to denote "raw" strings in TOML. 'ignore:function ham\(\) is deprecated:DeprecationWarning', ] diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 139140afdfa..4b3c939bccb 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -186,7 +186,7 @@ Add warning filters to marked test items. .. code-block:: python - @pytest.mark.filterwarnings("ignore:.*usage will be deprecated.*:DeprecationWarning") + @pytest.mark.filterwarnings(r"ignore:.*usage will be deprecated.*:DeprecationWarning") def test_foo(): ... @@ -1587,9 +1587,8 @@ passed multiple times. The expected format is ``name=value``. For example:: For more information please refer to :ref:`faulthandler`. For more information please refer to :ref:`faulthandler`. -.. confval:: filterwarnings - +.. confval:: filterwarnings Sets a list of filters and actions that should be taken for matched warnings. By default all warnings emitted during the test session @@ -1600,7 +1599,12 @@ passed multiple times. The expected format is ``name=value``. For example:: .. code-block:: toml [pytest] - filterwarnings = ["error", "ignore::DeprecationWarning"] + filterwarnings = [ + 'error', + 'ignore::DeprecationWarning', + # Note the use of single quote below to denote "raw" strings in TOML. + 'ignore:function ham\(\) should not be used:UserWarning', + ] .. tab:: ini @@ -1610,6 +1614,7 @@ passed multiple times. The expected format is ``name=value``. For example:: filterwarnings = error ignore::DeprecationWarning + ignore:function ham\(\) should not be used:UserWarning This tells pytest to ignore deprecation warnings and turn all other warnings into errors. For more information please refer to :ref:`warnings`. diff --git a/pyproject.toml b/pyproject.toml index 1f5835254da..58d17a42b6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -380,39 +380,39 @@ norecursedirs = [ ] strict = true filterwarnings = [ - "error", - "default:Using or importing the ABCs:DeprecationWarning:unittest2.*", + 'error', + 'default:Using or importing the ABCs:DeprecationWarning:unittest2.*', # produced by older pyparsing<=2.2.0. - "default:Using or importing the ABCs:DeprecationWarning:pyparsing.*", - "default:the imp module is deprecated in favour of importlib:DeprecationWarning:nose.*", + 'default:Using or importing the ABCs:DeprecationWarning:pyparsing.*', + 'default:the imp module is deprecated in favour of importlib:DeprecationWarning:nose.*', # distutils is deprecated in 3.10, scheduled for removal in 3.12 - "ignore:The distutils package is deprecated:DeprecationWarning", + 'ignore:The distutils package is deprecated:DeprecationWarning', # produced by pytest-xdist - "ignore:.*type argument to addoption.*:DeprecationWarning", + 'ignore:.*type argument to addoption.*:DeprecationWarning', # produced on execnet (pytest-xdist) - "ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning", + 'ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning', # pytest's own futurewarnings - "ignore::pytest.PytestExperimentalApiWarning", + 'ignore::pytest.PytestExperimentalApiWarning', # Do not cause SyntaxError for invalid escape sequences in py37. # Those are caught/handled by pyupgrade, and not easy to filter with the # module being the filename (with .py removed). - "default:invalid escape sequence:DeprecationWarning", + 'default:invalid escape sequence:DeprecationWarning', # ignore not yet fixed warnings for hook markers - "default:.*not marked using pytest.hook.*", - "ignore:.*not marked using pytest.hook.*::xdist.*", + 'default:.*not marked using pytest.hook.*', + 'ignore:.*not marked using pytest.hook.*::xdist.*', # ignore use of unregistered marks, because we use many to test the implementation - "ignore::_pytest.warning_types.PytestUnknownMarkWarning", + 'ignore::_pytest.warning_types.PytestUnknownMarkWarning', # https://github.com/benjaminp/six/issues/341 - "ignore:_SixMetaPathImporter\\.exec_module\\(\\) not found; falling back to load_module\\(\\):ImportWarning", + 'ignore:_SixMetaPathImporter\.exec_module\(\) not found; falling back to load_module\(\):ImportWarning', # https://github.com/benjaminp/six/pull/352 - "ignore:_SixMetaPathImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning", + 'ignore:_SixMetaPathImporter\.find_spec\(\) not found; falling back to find_module\(\):ImportWarning', # https://github.com/pypa/setuptools/pull/2517 - "ignore:VendorImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning", + 'ignore:VendorImporter\.find_spec\(\) not found; falling back to find_module\(\):ImportWarning', # https://github.com/pytest-dev/execnet/pull/127 - "ignore:isSet\\(\\) is deprecated, use is_set\\(\\) instead:DeprecationWarning", + 'ignore:isSet\(\) is deprecated, use is_set\(\) instead:DeprecationWarning', # https://github.com/pytest-dev/pytest/issues/2366 # https://github.com/pytest-dev/pytest/pull/13057 - "default::pytest.PytestFDWarning", + 'default::pytest.PytestFDWarning', ] pytester_example_dir = "testing/example_scripts" markers = [