Skip to content

Commit 9a8ce95

Browse files
miss-islingtonCharlieZhao95CAM-Gerlach
authored
gh-103109: Document ignore_warnings() test support helper (GH-103110)
(cherry picked from commit 32937d6) Co-authored-by: Charlie Zhao <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent d58ff6a commit 9a8ce95

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Doc/library/test.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,21 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes
16221622
.. versionadded:: 3.10
16231623

16241624

1625+
.. function:: ignore_warnings(*, category)
1626+
1627+
Suppress warnings that are instances of *category*,
1628+
which must be :exc:`Warning` or a subclass.
1629+
Roughly equivalent to :func:`warnings.catch_warnings`
1630+
with :meth:`warnings.simplefilter('ignore', category=category) <warnings.simplefilter>`.
1631+
For example::
1632+
1633+
@warning_helper.ignore_warnings(category=DeprecationWarning)
1634+
def test_suppress_warning():
1635+
# do something
1636+
1637+
.. versionadded:: 3.8
1638+
1639+
16251640
.. function:: check_no_resource_warning(testcase)
16261641

16271642
Context manager to check that no :exc:`ResourceWarning` was raised. You

Lib/test/support/warnings_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def check_syntax_warning(testcase, statement, errtext='',
3636

3737

3838
def ignore_warnings(*, category):
39-
"""Decorator to suppress deprecation warnings.
39+
"""Decorator to suppress warnings.
4040
4141
Use of context managers to hide warnings make diffs
4242
more noisy and tools like 'git blame' less useful.

0 commit comments

Comments
 (0)