MCPcopy Create free account
hub / github.com/PyO3/pyo3 / test_pyfunction_warn

Function test_pyfunction_warn

tests/test_pyfunction.rs:721–772  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

719
720#[test]
721fn test_pyfunction_warn() {
722 #[pyfunction]
723 #[pyo3(warn(message = "TPW: this function raises warning"))]
724 fn function_with_warning() {}
725
726 py_expect_warning_for_fn!(
727 function_with_warning,
728 f,
729 [("TPW: this function raises warning", PyUserWarning)]
730 );
731
732 #[pyfunction]
733 #[pyo3(warn(message = "TPW: this function raises warning with category", category = PyFutureWarning))]
734 fn function_with_warning_with_category() {}
735
736 py_expect_warning_for_fn!(
737 function_with_warning_with_category,
738 f,
739 [(
740 "TPW: this function raises warning with category",
741 PyFutureWarning
742 )]
743 );
744
745 #[pyfunction]
746 #[pyo3(warn(message = "TPW: custom deprecated category", category = pyo3::exceptions::PyDeprecationWarning))]
747 fn function_with_warning_with_custom_category() {}
748
749 py_expect_warning_for_fn!(
750 function_with_warning_with_custom_category,
751 f,
752 [(
753 "TPW: custom deprecated category",
754 pyo3::exceptions::PyDeprecationWarning
755 )]
756 );
757
758 #[cfg(any(not(Py_LIMITED_API), Py_3_12))]
759 #[pyfunction]
760 #[pyo3(warn(message = "TPW: this function raises user-defined warning", category = UserDefinedWarning))]
761 fn function_with_warning_and_user_defined_category() {}
762
763 #[cfg(any(not(Py_LIMITED_API), Py_3_12))]
764 py_expect_warning_for_fn!(
765 function_with_warning_and_user_defined_category,
766 f,
767 [(
768 "TPW: this function raises user-defined warning",
769 UserDefinedWarning
770 )]
771 );
772}
773
774#[test]
775fn test_pyfunction_multiple_warnings() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected