Skip to content

gh-103109: Add documentation for ignore_warnings #103110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,18 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes
.. versionadded:: 3.10


.. function:: ignore_warnings(*, category)

A decorator to suppress warnings. *category* is a subclass of :exc:`Warning`
class. It is approximately equivalent to calling :func:`warnings.catch_warnings()`
with :meth:`warnings.simplefilter` set to ``ignore``. If you want to suppress some
known warnings in test case, using code like the following::

@warning_helper.ignore_warnings(category=DeprecationWarning)
def test_suppress_warning():
# do something


.. function:: check_no_resource_warning(testcase)

Context manager to check that no :exc:`ResourceWarning` was raised. You
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/warnings_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down