Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/en/how-to/capture-warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

Expand Down
13 changes: 9 additions & 4 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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(): ...


Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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`.
Expand Down
34 changes: 17 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down