Skip to content

Commit

Permalink
Test for multiple warnings in pyfunction
Browse files Browse the repository at this point in the history
  • Loading branch information
FlickerSoul committed Jul 22, 2024
1 parent 53897de commit 8fbbc54
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
);
});
}

0 comments on commit 8fbbc54

Please sign in to comment.