pytest.warns
now validates that warnings.warn
was called with a str or a Warning. Currently in Python it is possible to use other types, however this causes an exception when warnings.filterwarnings
is used to filter those warnings (see CPython #103577 for a discussion). While this can be considered a bug in CPython, we decided to put guards in pytest as the error message produced without this check in place is confusing.