diff --git a/tests/test_pyfunction.rs b/tests/test_pyfunction.rs index ab6305101d7..a7aa042affc 100644 --- a/tests/test_pyfunction.rs +++ b/tests/test_pyfunction.rs @@ -672,3 +672,42 @@ fn test_pyfunction_deprecated() { ); }); } + +#[test] +fn test_pyfunction_multiple_warnings() { + #[pyfunction] + #[pyo3(warn(message = "this function raises warning"))] + #[pyo3(warn(message = "this function raises FutureWarning", category = PyFutureWarning))] + fn function_with_multiple_warnings() {} + + Python::with_gil(|py| { + let f = wrap_pyfunction_bound!(function_with_multiple_warnings)(py).unwrap(); + py_expect_warning!( + py, + f, + "f()", + [ + ("this function raises warning", PyUserWarning), + ("this function raises FutureWarning", PyFutureWarning) + ] + ); + }); + + #[pyfunction] + #[pyo3(warn(message = "this function raises warning"))] + #[pyo3(deprecated = "this function is deprecated")] + fn function_with_warning_and_deprecated() {} + + Python::with_gil(|py| { + let f = wrap_pyfunction_bound!(function_with_warning_and_deprecated)(py).unwrap(); + py_expect_warning!( + py, + f, + "f()", + [ + ("this function raises warning", PyUserWarning), + ("this function is deprecated", PyDeprecationWarning) + ] + ); + }); +}