Skip to content

Improve the documentation for ignore_warnings #103109

Description

@CharlieZhao95

Documentation

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

Activity

  1. added
    testsTests in the Lib/test dir
    type-featureA feature request or enhancement
    and removed
    docsDocumentation in the Doc dir
    on Mar 30, 2023
  2. added a commit that references this issue on Apr 2, 2023
  3. added 2 commits that reference this issue on Apr 2, 2023
  4. erlend-aasland commented on Apr 2, 2023

    @erlend-aasland
    Contributor

    Fixing the docstring and adding documentation seems enough for now. AFAIK, there is no need for adding a default value (consistency with warnings.simplefilter is not reason enough IMO). Marking this as closed.

  5. added 2 commits that reference this issue on Apr 2, 2023
  6. added a commit that references this issue on Apr 8, 2023
  7. added a commit that references this issue on Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions