This commit is contained in:
mejrs 2022-12-28 23:11:39 +01:00
parent 44310ec7e0
commit 5198722dd9
1 changed files with 24 additions and 0 deletions

24
tests/test_field_cfg.rs Normal file
View File

@ -0,0 +1,24 @@
#![cfg(feature = "macros")]
use pyo3::prelude::*;
#[pyclass]
struct CfgClass {
#[pyo3(get, set)]
#[cfg(any())]
pub a: u32,
#[pyo3(get, set)]
#[cfg(all())]
pub b: u32,
}
#[test]
fn test_cfg() {
Python::with_gil(|py| {
let cfg = CfgClass { b: 3 };
let py_cfg = Py::new(py, cfg).unwrap();
assert!(py_cfg.as_ref(py).getattr("a").is_err());
let b: u32 = py_cfg.as_ref(py).getattr("b").unwrap().extract().unwrap();
assert_eq!(b, 3);
});
}