Skip to content

Commit 786dda6

Browse files
authored
Merge pull request #13937 from bluetech/filterwarnings-toml
Use raw Python and raw TOML strings in `filterwarnings`
2 parents 1be877d + 4ae47b7 commit 786dda6

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

doc/en/how-to/capture-warnings.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ all other warnings into errors.
9191
9292
[pytest]
9393
filterwarnings = [
94-
"error",
95-
"ignore::UserWarning",
96-
# note the use of single quote below to denote "raw" strings in TOML
94+
'error',
95+
'ignore::UserWarning',
96+
# Note the use of single quote below to denote "raw" strings in TOML.
9797
'ignore:function ham\(\) is deprecated:DeprecationWarning',
9898
]
9999

doc/en/reference/reference.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Add warning filters to marked test items.
186186

187187
.. code-block:: python
188188
189-
@pytest.mark.filterwarnings("ignore:.*usage will be deprecated.*:DeprecationWarning")
189+
@pytest.mark.filterwarnings(r"ignore:.*usage will be deprecated.*:DeprecationWarning")
190190
def test_foo(): ...
191191
192192
@@ -1587,9 +1587,8 @@ passed multiple times. The expected format is ``name=value``. For example::
15871587
For more information please refer to :ref:`faulthandler`.
15881588
For more information please refer to :ref:`faulthandler`.
15891589

1590-
.. confval:: filterwarnings
1591-
15921590

1591+
.. confval:: filterwarnings
15931592

15941593
Sets a list of filters and actions that should be taken for matched
15951594
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::
16001599
.. code-block:: toml
16011600
16021601
[pytest]
1603-
filterwarnings = ["error", "ignore::DeprecationWarning"]
1602+
filterwarnings = [
1603+
'error',
1604+
'ignore::DeprecationWarning',
1605+
# Note the use of single quote below to denote "raw" strings in TOML.
1606+
'ignore:function ham\(\) should not be used:UserWarning',
1607+
]
16041608
16051609
.. tab:: ini
16061610

@@ -1610,6 +1614,7 @@ passed multiple times. The expected format is ``name=value``. For example::
16101614
filterwarnings =
16111615
error
16121616
ignore::DeprecationWarning
1617+
ignore:function ham\(\) should not be used:UserWarning
16131618
16141619
This tells pytest to ignore deprecation warnings and turn all other warnings
16151620
into errors. For more information please refer to :ref:`warnings`.

pyproject.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -380,39 +380,39 @@ norecursedirs = [
380380
]
381381
strict = true
382382
filterwarnings = [
383-
"error",
384-
"default:Using or importing the ABCs:DeprecationWarning:unittest2.*",
383+
'error',
384+
'default:Using or importing the ABCs:DeprecationWarning:unittest2.*',
385385
# produced by older pyparsing<=2.2.0.
386-
"default:Using or importing the ABCs:DeprecationWarning:pyparsing.*",
387-
"default:the imp module is deprecated in favour of importlib:DeprecationWarning:nose.*",
386+
'default:Using or importing the ABCs:DeprecationWarning:pyparsing.*',
387+
'default:the imp module is deprecated in favour of importlib:DeprecationWarning:nose.*',
388388
# distutils is deprecated in 3.10, scheduled for removal in 3.12
389-
"ignore:The distutils package is deprecated:DeprecationWarning",
389+
'ignore:The distutils package is deprecated:DeprecationWarning',
390390
# produced by pytest-xdist
391-
"ignore:.*type argument to addoption.*:DeprecationWarning",
391+
'ignore:.*type argument to addoption.*:DeprecationWarning',
392392
# produced on execnet (pytest-xdist)
393-
"ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning",
393+
'ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning',
394394
# pytest's own futurewarnings
395-
"ignore::pytest.PytestExperimentalApiWarning",
395+
'ignore::pytest.PytestExperimentalApiWarning',
396396
# Do not cause SyntaxError for invalid escape sequences in py37.
397397
# Those are caught/handled by pyupgrade, and not easy to filter with the
398398
# module being the filename (with .py removed).
399-
"default:invalid escape sequence:DeprecationWarning",
399+
'default:invalid escape sequence:DeprecationWarning',
400400
# ignore not yet fixed warnings for hook markers
401-
"default:.*not marked using pytest.hook.*",
402-
"ignore:.*not marked using pytest.hook.*::xdist.*",
401+
'default:.*not marked using pytest.hook.*',
402+
'ignore:.*not marked using pytest.hook.*::xdist.*',
403403
# ignore use of unregistered marks, because we use many to test the implementation
404-
"ignore::_pytest.warning_types.PytestUnknownMarkWarning",
404+
'ignore::_pytest.warning_types.PytestUnknownMarkWarning',
405405
# https://github.com/benjaminp/six/issues/341
406-
"ignore:_SixMetaPathImporter\\.exec_module\\(\\) not found; falling back to load_module\\(\\):ImportWarning",
406+
'ignore:_SixMetaPathImporter\.exec_module\(\) not found; falling back to load_module\(\):ImportWarning',
407407
# https://github.com/benjaminp/six/pull/352
408-
"ignore:_SixMetaPathImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
408+
'ignore:_SixMetaPathImporter\.find_spec\(\) not found; falling back to find_module\(\):ImportWarning',
409409
# https://github.com/pypa/setuptools/pull/2517
410-
"ignore:VendorImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
410+
'ignore:VendorImporter\.find_spec\(\) not found; falling back to find_module\(\):ImportWarning',
411411
# https://github.com/pytest-dev/execnet/pull/127
412-
"ignore:isSet\\(\\) is deprecated, use is_set\\(\\) instead:DeprecationWarning",
412+
'ignore:isSet\(\) is deprecated, use is_set\(\) instead:DeprecationWarning',
413413
# https://github.com/pytest-dev/pytest/issues/2366
414414
# https://github.com/pytest-dev/pytest/pull/13057
415-
"default::pytest.PytestFDWarning",
415+
'default::pytest.PytestFDWarning',
416416
]
417417
pytester_example_dir = "testing/example_scripts"
418418
markers = [

0 commit comments

Comments
 (0)