def test_raise_type_error_on_invalid_warning() -> None:
    """Check pytest.warns validates warning messages are strings (#10865) or
    Warning instances (#11959)."""
    with pytest.raises(TypeError, match="Warning must be str or Warning"):
        with pytest.warns(UserWarning):
            warnings.warn(1)  # type: ignore
Check pytest.warns validates warning messages are strings (#10865) or
    Warning instances (#11959).
testing/test_recwarn.py