◐ Shell
clean mode source ↗

Improve the documentation for `ignore_warnings`

Recently, I found that using ignore_warnings(*, category), a simple decorator in test.support.warning_helper, is sometimes a concise way to suppress warnings in test cases. For example:

# use `with` statement
def test_suppress_warning():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=SyntaxWarning)
        # do something

# use decorator
@warning_helper.ignore_warnings(category=SyntaxWarning)
def test_suppress_warning():
    # do something

What I want to improve:

  1. The comment of function ignore_warnings , it writes

Decorator to suppress deprecation warnings

But in fact this can become a more general warning suppression decorator, not just deprecation warnings, we can improve this comment.

  1. The document of test.support.warnings_helper, it is missing information about the function ignore_warnings.
  2. Perhaps we can also add a default value to it, just like ignore_warnings(*, category=Warning), so that the behavior of this decorator is consistent with warnings.simplefilter.

Linked PRs