Skip to content

Commit 1c98858

Browse files
authored
skip tests using thread-unsafe constructs on free-threaded build (#4476)
* skip tests using thread-unsafe constructs on free-threaded build * fix clippy with features=full
1 parent 07da500 commit 1c98858

7 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/conversions/chrono.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ mod tests {
10981098

10991099
check_utc("regular", 2014, 5, 6, 7, 8, 9, 999_999, 999_999);
11001100

1101+
#[cfg(not(Py_GIL_DISABLED))]
11011102
assert_warnings!(
11021103
py,
11031104
check_utc("leap second", 2014, 5, 6, 7, 8, 59, 1_999_999, 999_999),
@@ -1140,6 +1141,7 @@ mod tests {
11401141

11411142
check_fixed_offset("regular", 2014, 5, 6, 7, 8, 9, 999_999, 999_999);
11421143

1144+
#[cfg(not(Py_GIL_DISABLED))]
11431145
assert_warnings!(
11441146
py,
11451147
check_fixed_offset("leap second", 2014, 5, 6, 7, 8, 59, 1_999_999, 999_999),
@@ -1295,6 +1297,7 @@ mod tests {
12951297

12961298
check_time("regular", 3, 5, 7, 999_999, 999_999);
12971299

1300+
#[cfg(not(Py_GIL_DISABLED))]
12981301
assert_warnings!(
12991302
py,
13001303
check_time("leap second", 3, 5, 59, 1_999_999, 999_999),
@@ -1342,7 +1345,7 @@ mod tests {
13421345
.unwrap()
13431346
}
13441347

1345-
#[cfg(not(target_arch = "wasm32"))]
1348+
#[cfg(not(any(target_arch = "wasm32", Py_GIL_DISABLED)))]
13461349
mod proptests {
13471350
use super::*;
13481351
use crate::tests::common::CatchWarnings;

src/err/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ mod tests {
12481248
warnings.call_method0("resetwarnings").unwrap();
12491249

12501250
// First, test the warning is emitted
1251+
#[cfg(not(Py_GIL_DISABLED))]
12511252
assert_warnings!(
12521253
py,
12531254
{ PyErr::warn(py, &cls, ffi::c_str!("I am warning you"), 0).unwrap() },
@@ -1267,6 +1268,7 @@ mod tests {
12671268
.unwrap();
12681269

12691270
// This has the wrong module and will not raise, just be emitted
1271+
#[cfg(not(Py_GIL_DISABLED))]
12701272
assert_warnings!(
12711273
py,
12721274
{ PyErr::warn(py, &cls, ffi::c_str!("I am warning you"), 0).unwrap() },

src/tests/common.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ mod inner {
99
#[allow(unused_imports)] // pulls in `use crate as pyo3` in `test_utils.rs`
1010
use super::*;
1111

12+
#[cfg(not(Py_GIL_DISABLED))]
1213
use pyo3::prelude::*;
1314

15+
#[cfg(not(Py_GIL_DISABLED))]
1416
use pyo3::types::{IntoPyDict, PyList};
1517

1618
#[macro_export]
@@ -63,14 +65,14 @@ mod inner {
6365
}
6466

6567
// sys.unraisablehook not available until Python 3.8
66-
#[cfg(all(feature = "macros", Py_3_8))]
68+
#[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))]
6769
#[pyclass(crate = "pyo3")]
6870
pub struct UnraisableCapture {
6971
pub capture: Option<(PyErr, PyObject)>,
7072
old_hook: Option<PyObject>,
7173
}
7274

73-
#[cfg(all(feature = "macros", Py_3_8))]
75+
#[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))]
7476
#[pymethods(crate = "pyo3")]
7577
impl UnraisableCapture {
7678
pub fn hook(&mut self, unraisable: Bound<'_, PyAny>) {
@@ -80,7 +82,7 @@ mod inner {
8082
}
8183
}
8284

83-
#[cfg(all(feature = "macros", Py_3_8))]
85+
#[cfg(all(feature = "macros", Py_3_8, not(Py_GIL_DISABLED)))]
8486
impl UnraisableCapture {
8587
pub fn install(py: Python<'_>) -> Py<Self> {
8688
let sys = py.import("sys").unwrap();
@@ -109,10 +111,12 @@ mod inner {
109111
}
110112
}
111113

114+
#[cfg(not(Py_GIL_DISABLED))]
112115
pub struct CatchWarnings<'py> {
113116
catch_warnings: Bound<'py, PyAny>,
114117
}
115118

119+
#[cfg(not(Py_GIL_DISABLED))]
116120
impl<'py> CatchWarnings<'py> {
117121
pub fn enter<R>(
118122
py: Python<'py>,
@@ -129,6 +133,7 @@ mod inner {
129133
}
130134
}
131135

136+
#[cfg(not(Py_GIL_DISABLED))]
132137
impl Drop for CatchWarnings<'_> {
133138
fn drop(&mut self) {
134139
let py = self.catch_warnings.py();
@@ -138,6 +143,7 @@ mod inner {
138143
}
139144
}
140145

146+
#[cfg(not(Py_GIL_DISABLED))]
141147
#[macro_export]
142148
macro_rules! assert_warnings {
143149
($py:expr, $body:expr, [$(($category:ty, $message:literal)),+] $(,)? ) => {{

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[macro_use]
22
pub(crate) mod common {
3+
#[cfg(not(Py_GIL_DISABLED))]
34
use crate as pyo3;
45
include!("./common.rs");
56
}

tests/test_buffer_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn test_buffer_referenced() {
9494
}
9595

9696
#[test]
97-
#[cfg(Py_3_8)] // sys.unraisablehook not available until Python 3.8
97+
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8
9898
fn test_releasebuffer_unraisable_error() {
9999
use common::UnraisableCapture;
100100
use pyo3::exceptions::PyValueError;

tests/test_class_basics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ fn access_frozen_class_without_gil() {
615615
}
616616

617617
#[test]
618-
#[cfg(Py_3_8)] // sys.unraisablehook not available until Python 3.8
618+
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8
619619
#[cfg_attr(target_arch = "wasm32", ignore)]
620620
fn drop_unsendable_elsewhere() {
621621
use common::UnraisableCapture;

tests/test_exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn test_exception_nosegfault() {
9999
}
100100

101101
#[test]
102-
#[cfg(Py_3_8)]
102+
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))]
103103
fn test_write_unraisable() {
104104
use common::UnraisableCapture;
105105
use pyo3::{exceptions::PyRuntimeError, ffi, types::PyNotImplemented};

0 commit comments

Comments
 (0)