diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-04-02 22:42:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-02 22:42:43 (GMT) |
commit | 0854bdf15f93f0a4bad44dc3955b713c721c394f (patch) | |
tree | 76ad256f8b6de69cdde01b71c6e3e4ddb8aeedfb | |
parent | 4664a7cf689946f0c9854cadee7c6aa9c276a8cf (diff) | |
download | cpython-0854bdf15f93f0a4bad44dc3955b713c721c394f.zip cpython-0854bdf15f93f0a4bad44dc3955b713c721c394f.tar.gz cpython-0854bdf15f93f0a4bad44dc3955b713c721c394f.tar.bz2 |
gh-103109: Document ignore_warnings() test support helper (GH-103110)
(cherry picked from commit 32937d6aa414ec7db5c63ef277f21db1880b3af4)
Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
-rw-r--r-- | Doc/library/test.rst | 15 | ||||
-rw-r--r-- | Lib/test/support/warnings_helper.py | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 8e05ff3..0bddd31 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -1631,6 +1631,21 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes .. 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) Context manager to check that no :exc:`ResourceWarning` was raised. You diff --git a/Lib/test/support/warnings_helper.py b/Lib/test/support/warnings_helper.py index 28e96f88..c1bf056 100644 --- a/Lib/test/support/warnings_helper.py +++ b/Lib/test/support/warnings_helper.py @@ -44,7 +44,7 @@ def check_syntax_warning(testcase, statement, errtext='', def ignore_warnings(*, category): - """Decorator to suppress deprecation warnings. + """Decorator to suppress warnings. Use of context managers to hide warnings make diffs more noisy and tools like 'git blame' less useful. |