Skip to content

Conversation

@maksverver
Copy link

With pytest>=7.0, warns(None) fails with:

TypeError: exceptions must be derived from Warning, not <class 'NoneType'>

The recommended solution is to use warnings.simplefilter("error") instead. See: https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests

What does this PR do?

Fixes broken tests.

Before submitting

  • Did you have fun?
    • Not really
  • Did you read the contributor guideline?
    • Yes
  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
    • No
  • Did you make sure to update the docs?
    • N/A
  • Did you write any new necessary tests?
    • N/A
  • Did you update the changelog? (if needed)
    • No, because I didn't change any production code, only tests.

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

With pytest>=7.0, `warns(None)` fails with:

  TypeError: exceptions must be derived from Warning, not <class 'NoneType'>

The recommended solution is to use `warnings.simplefilter("error")` instead. See:
https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant