From 2629301ecec8447af9c9aad9108fd9402647be80 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Fri, 23 Aug 2024 14:32:16 -0600 Subject: [PATCH 1/2] skip tests using thread-unsafe constructs on free-threaded build --- src/conversions/chrono.rs | 2 +- src/err/mod.rs | 2 ++ src/tests/common.rs | 12 +++++++++--- src/tests/mod.rs | 1 + tests/test_buffer_protocol.rs | 2 +- tests/test_class_basics.rs | 2 +- tests/test_exceptions.rs | 2 +- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index 48246d827db..cf4e235a306 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -1340,7 +1340,7 @@ mod tests { .unwrap() } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(any(target_arch = "wasm32", Py_GIL_DISABLED)))] mod proptests { use super::*; use crate::tests::common::CatchWarnings; diff --git a/src/err/mod.rs b/src/err/mod.rs index 68d207c8fb8..7eb75a4c587 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -1159,6 +1159,7 @@ mod tests { warnings.call_method0("resetwarnings").unwrap(); // First, test the warning is emitted + #[cfg(not(Py_GIL_DISABLED))] assert_warnings!( py, { PyErr::warn_bound(py, &cls, "I am warning you", 0).unwrap() }, @@ -1178,6 +1179,7 @@ mod tests { .unwrap(); // This has the wrong module and will not raise, just be emitted + #[cfg(not(Py_GIL_DISABLED))] assert_warnings!( py, { PyErr::warn_bound(py, &cls, "I am warning you", 0).unwrap() }, diff --git a/src/tests/common.rs b/src/tests/common.rs index 83c2f911672..a683bcca9a0 100644 --- a/src/tests/common.rs +++ b/src/tests/common.rs @@ -9,8 +9,10 @@ mod inner { #[allow(unused_imports)] // pulls in `use crate as pyo3` in `test_utils.rs` use super::*; + #[cfg(not(Py_GIL_DISABLED))] use pyo3::prelude::*; + #[cfg(not(Py_GIL_DISABLED))] use pyo3::types::{IntoPyDict, PyList}; #[macro_export] @@ -63,14 +65,14 @@ mod inner { } // sys.unraisablehook not available until Python 3.8 - #[cfg(all(feature = "macros", Py_3_8))] + #[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))] #[pyclass(crate = "pyo3")] pub struct UnraisableCapture { pub capture: Option<(PyErr, PyObject)>, old_hook: Option, } - #[cfg(all(feature = "macros", Py_3_8))] + #[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))] #[pymethods(crate = "pyo3")] impl UnraisableCapture { pub fn hook(&mut self, unraisable: Bound<'_, PyAny>) { @@ -80,7 +82,7 @@ mod inner { } } - #[cfg(all(feature = "macros", Py_3_8))] + #[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))] impl UnraisableCapture { pub fn install(py: Python<'_>) -> Py { let sys = py.import("sys").unwrap(); @@ -109,10 +111,12 @@ mod inner { } } + #[cfg(not(Py_GIL_DISABLED))] pub struct CatchWarnings<'py> { catch_warnings: Bound<'py, PyAny>, } + #[cfg(not(Py_GIL_DISABLED))] impl<'py> CatchWarnings<'py> { pub fn enter( py: Python<'py>, @@ -129,6 +133,7 @@ mod inner { } } + #[cfg(not(Py_GIL_DISABLED))] impl Drop for CatchWarnings<'_> { fn drop(&mut self) { let py = self.catch_warnings.py(); @@ -138,6 +143,7 @@ mod inner { } } + #[cfg(not(Py_GIL_DISABLED))] #[macro_export] macro_rules! assert_warnings { ($py:expr, $body:expr, [$(($category:ty, $message:literal)),+] $(,)? ) => {{ diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 7e78b6f19bd..136236d7db0 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,5 +1,6 @@ #[macro_use] pub(crate) mod common { + #[cfg(not(Py_GIL_DISABLED))] use crate as pyo3; include!("./common.rs"); } diff --git a/tests/test_buffer_protocol.rs b/tests/test_buffer_protocol.rs index 6ee7b0db328..4d3efec3e4f 100644 --- a/tests/test_buffer_protocol.rs +++ b/tests/test_buffer_protocol.rs @@ -94,7 +94,7 @@ fn test_buffer_referenced() { } #[test] -#[cfg(Py_3_8)] // sys.unraisablehook not available until Python 3.8 +#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8 fn test_releasebuffer_unraisable_error() { use common::UnraisableCapture; use pyo3::exceptions::PyValueError; diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index 5b91ca9e695..a6fb89831cc 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -615,7 +615,7 @@ fn access_frozen_class_without_gil() { } #[test] -#[cfg(Py_3_8)] // sys.unraisablehook not available until Python 3.8 +#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8 #[cfg_attr(target_arch = "wasm32", ignore)] fn drop_unsendable_elsewhere() { use common::UnraisableCapture; diff --git a/tests/test_exceptions.rs b/tests/test_exceptions.rs index cc823136997..fa3ac99ef62 100644 --- a/tests/test_exceptions.rs +++ b/tests/test_exceptions.rs @@ -99,7 +99,7 @@ fn test_exception_nosegfault() { } #[test] -#[cfg(Py_3_8)] +#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] fn test_write_unraisable() { use common::UnraisableCapture; use pyo3::{exceptions::PyRuntimeError, ffi, types::PyNotImplemented}; From dd4218cacbeea3e83997f9a67df70675c1c1beb4 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Sat, 24 Aug 2024 06:32:37 -0600 Subject: [PATCH 2/2] fix clippy with features=full --- src/conversions/chrono.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index cf4e235a306..83fb20290ef 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -1096,6 +1096,7 @@ mod tests { check_utc("regular", 2014, 5, 6, 7, 8, 9, 999_999, 999_999); + #[cfg(not(Py_GIL_DISABLED))] assert_warnings!( py, check_utc("leap second", 2014, 5, 6, 7, 8, 59, 1_999_999, 999_999), @@ -1138,6 +1139,7 @@ mod tests { check_fixed_offset("regular", 2014, 5, 6, 7, 8, 9, 999_999, 999_999); + #[cfg(not(Py_GIL_DISABLED))] assert_warnings!( py, check_fixed_offset("leap second", 2014, 5, 6, 7, 8, 59, 1_999_999, 999_999), @@ -1293,6 +1295,7 @@ mod tests { check_time("regular", 3, 5, 7, 999_999, 999_999); + #[cfg(not(Py_GIL_DISABLED))] assert_warnings!( py, check_time("leap second", 3, 5, 59, 1_999_999, 999_999),