Skip to content
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

Allow using warnings.warn() with a Warning #11959

Merged
merged 2 commits into from
Feb 16, 2024

Commits on Feb 16, 2024

  1. recwarn: minor style improvements

    In preparation for next commit.
    bluetech committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    dcf9da9 View commit details
    Browse the repository at this point in the history
  2. Allow using warnings.warn() with Warnings

    Test:
    
    `warnings.warn()` expects that its first argument is a `str` or a
    `Warning`, but since 9454fc3
    `pytest.warns()` no longer allows `Warning` instances unless the first
    argument the `Warning` was initialized with is a `str`. Furthermore, if
    the `Warning` was created without arguments then `pytest.warns()` raises
    an unexpected `IndexError`. The new tests reveal the problem.
    
    Fix:
    
    `pytest.warns()` now allows using `warnings.warn()` with a `Warning`
    instance, as is required by Python, with one exception. If the warning
    used is a `UserWarning` that was created by passing it arguments and the
    first argument was not a `str` then `pytest.raises()` still considers
    that an error. This is because if an invalid type was used in
    `warnings.warn()` then Python creates a `UserWarning` anyways and it
    becomes impossible for `pytest` to figure out if that was done
    automatically or not.
    
    [ran: rebased on previous commit]
    eerovaher authored and bluetech committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    0475b1c View commit details
    Browse the repository at this point in the history