Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ fn py_time_to_naive_time(py_time: &Bound<'_, PyAny>) -> PyResult<NaiveTime> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{types::PyTuple, BoundObject};
use crate::{test_utils::assert_warnings, types::PyTuple, BoundObject};
use std::{cmp::Ordering, panic};

#[test]
Expand Down Expand Up @@ -875,7 +875,6 @@ 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),
Expand Down Expand Up @@ -915,7 +914,6 @@ 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),
Expand Down Expand Up @@ -1101,7 +1099,6 @@ 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),
Expand Down Expand Up @@ -1163,10 +1160,10 @@ mod tests {
.unwrap()
}

#[cfg(not(any(target_arch = "wasm32", Py_GIL_DISABLED)))]
#[cfg(not(any(target_arch = "wasm32")))]
mod proptests {
use super::*;
use crate::tests::common::CatchWarnings;
use crate::test_utils::CatchWarnings;
use crate::types::IntoPyDict;
use proptest::prelude::*;
use std::ffi::CString;
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/num_bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn int_n_bits(long: &Bound<'_, PyInt>) -> PyResult<usize> {
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::common::generate_unique_module_name;
use crate::test_utils::generate_unique_module_name;
use crate::types::{PyAnyMethods as _, PyDict, PyModule};
use indoc::indoc;
use pyo3_ffi::c_str;
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/num_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ complex_conversion!(f64);
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::common::generate_unique_module_name;
use crate::test_utils::generate_unique_module_name;
use crate::types::PyAnyMethods as _;
use crate::types::{complex::PyComplexMethods, PyModule};
use crate::IntoPyObject;
Expand Down
3 changes: 1 addition & 2 deletions src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ mod tests {
use super::PyErrState;
use crate::exceptions::{self, PyTypeError, PyValueError};
use crate::impl_::pyclass::{value_of, IsSend, IsSync};
use crate::test_utils::assert_warnings;
use crate::{ffi, PyErr, PyTypeInfo, Python};

#[test]
Expand Down Expand Up @@ -1052,7 +1053,6 @@ mod tests {
warnings.call_method0("resetwarnings").unwrap();

// First, test the warning is emitted
#[cfg(not(Py_GIL_DISABLED))]
assert_warnings!(
py,
{ PyErr::warn(py, &cls, ffi::c_str!("I am warning you"), 0).unwrap() },
Expand All @@ -1072,7 +1072,6 @@ 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(py, &cls, ffi::c_str!("I am warning you"), 0).unwrap() },
Expand Down
2 changes: 1 addition & 1 deletion src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ impl Py<PyAny> {
#[cfg(test)]
mod tests {
use super::{Bound, IntoPyObject, Py};
use crate::tests::common::generate_unique_module_name;
use crate::test_utils::generate_unique_module_name;
use crate::types::{dict::IntoPyDict, PyAnyMethods, PyCapsule, PyDict, PyString};
use crate::{ffi, Borrowed, PyAny, PyResult, Python};
use pyo3_ffi::c_str;
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ pub use inventory; // Re-exported for `#[pyclass]` and `#[pymethods]` with `mult
/// Tests and helpers which reside inside PyO3's main library. Declared first so that macros
/// are available in unit tests.
#[cfg(test)]
#[macro_use]
mod test_utils;
#[cfg(test)]
mod tests;

// Macro dependencies, also contains macros exported for use across the codebase and
Expand Down
6 changes: 6 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Brings in `test_utils` from the `tests` directory
//
// to make that file function (lots of references to `pyo3` within it) need
// re-bind `crate` as pyo3
use crate as pyo3;
include!("../tests/test_utils/mod.rs");
7 changes: 0 additions & 7 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#[macro_use]
pub(crate) mod common {
#[cfg(not(Py_GIL_DISABLED))]
use crate as pyo3;
include!("./common.rs");
}

/// Test macro hygiene - this is in the crate since we won't have
/// `pyo3` available in the crate root.
#[cfg(all(test, feature = "macros"))]
Expand Down
2 changes: 1 addition & 1 deletion src/types/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ mod tests {
use crate::{
basic::CompareOp,
ffi,
tests::common::generate_unique_module_name,
test_utils::generate_unique_module_name,
types::{IntoPyDict, PyAny, PyAnyMethods, PyBool, PyInt, PyList, PyModule, PyTypeMethods},
Bound, BoundObject, IntoPyObject, PyTypeInfo, Python,
};
Expand Down
2 changes: 1 addition & 1 deletion src/types/typeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<'py> PyTypeMethods<'py> for Bound<'py, PyType> {

#[cfg(test)]
mod tests {
use crate::tests::common::generate_unique_module_name;
use crate::test_utils::generate_unique_module_name;
use crate::types::{PyAnyMethods, PyBool, PyInt, PyModule, PyTuple, PyType, PyTypeMethods};
use crate::PyAny;
use crate::Python;
Expand Down
3 changes: 1 addition & 2 deletions tests/test_arithmetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use pyo3::class::basic::CompareOp;
use pyo3::py_run;
use pyo3::{prelude::*, BoundObject};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
struct UnaryArithmetic {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::{
};

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

enum TestGetBufferError {
NullShape,
Expand Down
5 changes: 2 additions & 3 deletions tests/test_buffer_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
struct TestBufferClass {
Expand Down Expand Up @@ -98,8 +97,8 @@ fn test_buffer_referenced() {
#[test]
#[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;
use test_utils::UnraisableCapture;

#[pyclass]
struct ReleaseBufferError {}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use pyo3::prelude::*;
use pyo3::types::PyBytes;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyfunction]
fn bytes_pybytes_conversion(bytes: &[u8]) -> &[u8] {
Expand Down
5 changes: 2 additions & 3 deletions tests/test_class_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use pyo3::prelude::*;
use pyo3::py_run;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
struct Foo {
Expand Down Expand Up @@ -154,8 +153,8 @@ fn recursive_class_attributes() {
#[test]
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))] // sys.unraisablehook not available until Python 3.8
fn test_fallible_class_attribute() {
use common::UnraisableCapture;
use pyo3::exceptions::PyValueError;
use test_utils::UnraisableCapture;

#[pyclass]
struct BrokenClass;
Expand Down
5 changes: 2 additions & 3 deletions tests/test_class_basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use pyo3::prelude::*;
use pyo3::types::PyType;
use pyo3::{py_run, PyClass};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
struct EmptyClass {}
Expand Down Expand Up @@ -619,12 +618,12 @@ fn access_frozen_class_without_gil() {
#[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;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use std::thread::spawn;
use test_utils::UnraisableCapture;

#[pyclass(unsendable)]
struct Unsendable {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_class_comparisons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use pyo3::prelude::*;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass(eq)]
#[derive(Debug, Clone, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_class_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use pyo3::prelude::*;

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
#[derive(Clone, Debug, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_class_formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use pyo3::prelude::*;
use pyo3::py_run;
use std::fmt::{Display, Formatter};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass(eq, str)]
#[derive(Debug, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use pyo3::{
#[cfg(target_has_atomic = "64")]
use std::sync::atomic::{AtomicBool, Ordering};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

fn handle_windows(test: &str) -> String {
let set_event_loop_policy = r#"
Expand Down
3 changes: 1 addition & 2 deletions tests/test_declarative_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use pyo3::exceptions::PyException;
use pyo3::prelude::*;
use pyo3::sync::OnceLockExt;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

mod some_module {
use pyo3::create_exception;
Expand Down
3 changes: 1 addition & 2 deletions tests/test_default_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use pyo3::prelude::*;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

// Test default generated __repr__.
#[pyclass(eq, eq_int)]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use pyo3::prelude::*;
use pyo3::py_run;
use pyo3::types::PyString;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass(eq, eq_int)]
#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions tests/test_exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::fmt;
#[cfg(not(target_os = "windows"))]
use std::fs::File;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyfunction]
#[cfg(not(target_os = "windows"))]
Expand Down Expand Up @@ -101,9 +100,9 @@ fn test_exception_nosegfault() {
#[test]
#[cfg(all(Py_3_8, not(Py_GIL_DISABLED)))]
fn test_write_unraisable() {
use common::UnraisableCapture;
use pyo3::{exceptions::PyRuntimeError, ffi, types::PyNotImplemented};
use std::ptr;
use test_utils::UnraisableCapture;

Python::attach(|py| {
let capture = UnraisableCapture::install(py);
Expand Down
3 changes: 1 addition & 2 deletions tests/test_frompy_intopy_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::collections::HashMap;
use std::hash::Hash;

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[derive(Debug, Clone, IntoPyObject, IntoPyObjectRef, FromPyObject)]
pub struct A<'py> {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_frompyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use pyo3::prelude::*;
use pyo3::types::{IntoPyDict, PyDict, PyList, PyString, PyTuple};

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

/// Helper function that concatenates the error message from
/// each error in the traceback into a single string that can
Expand Down
3 changes: 1 addition & 2 deletions tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;
use std::sync::{Arc, Mutex};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass(freelist = 2)]
struct ClassWithFreelist {}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_getter_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use pyo3::py_run;
use pyo3::types::PyString;
use pyo3::types::{IntoPyDict, PyList};

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
struct ClassWithProperties {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use pyo3::py_run;
use pyo3::ffi;
use pyo3::types::IntoPyDict;

#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass(subclass)]
struct BaseClass {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_intopyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::collections::HashMap;
use std::hash::Hash;

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[derive(Debug, IntoPyObject)]
pub struct A<'py> {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_macro_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

#[macro_use]
#[path = "../src/tests/common.rs"]
mod common;
mod test_utils;

#[pyclass]
/// The MacroDocs class.
Expand Down
Loading
Loading