gh-103109: Document ignore_warnings() test support helper (GH-103110)

(cherry picked from commit 32937d6aa4)

Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
Miss Islington (bot) 2023-04-02 15:42:43 -07:00 committed by GitHub
parent 4664a7cf68
commit 0854bdf15f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -1631,6 +1631,21 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes
.. versionadded:: 3.10 .. versionadded:: 3.10
.. function:: ignore_warnings(*, category)
Suppress warnings that are instances of *category*,
which must be :exc:`Warning` or a subclass.
Roughly equivalent to :func:`warnings.catch_warnings`
with :meth:`warnings.simplefilter('ignore', category=category) <warnings.simplefilter>`.
For example::
@warning_helper.ignore_warnings(category=DeprecationWarning)
def test_suppress_warning():
# do something
.. versionadded:: 3.8
.. function:: check_no_resource_warning(testcase) .. function:: check_no_resource_warning(testcase)
Context manager to check that no :exc:`ResourceWarning` was raised. You Context manager to check that no :exc:`ResourceWarning` was raised. You

View file

@ -44,7 +44,7 @@ def check_syntax_warning(testcase, statement, errtext='',
def ignore_warnings(*, category): def ignore_warnings(*, category):
"""Decorator to suppress deprecation warnings. """Decorator to suppress warnings.
Use of context managers to hide warnings make diffs Use of context managers to hide warnings make diffs
more noisy and tools like 'git blame' less useful. more noisy and tools like 'git blame' less useful.