Skip to content

Commit

Permalink
fix pytests for abi3 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Aug 29, 2024
1 parent 9d1a057 commit 744a283
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pytests/src/pyclasses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ impl AssertingBaseClass {
#[pyclass]
struct ClassWithoutConstructor;

#[cfg(any(Py_3_10, not(Py_LIMITED_API)))]
#[pyclass(dict)]
struct ClassWithDict;

#[cfg(any(Py_3_10, not(Py_LIMITED_API)))]
#[pymethods]
impl ClassWithDict {
#[new]
Expand All @@ -83,6 +85,7 @@ pub fn pyclasses(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyClassIter>()?;
m.add_class::<AssertingBaseClass>()?;
m.add_class::<ClassWithoutConstructor>()?;
#[cfg(any(Py_3_10, not(Py_LIMITED_API)))]
m.add_class::<ClassWithDict>()?;

Ok(())
Expand Down
7 changes: 6 additions & 1 deletion pytests/tests/test_pyclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def test_no_constructor_defined_propagates_cause(cls: Type):


def test_dict():
d = pyclasses.ClassWithDict()
try:
ClassWithDict = pyclasses.ClassWithDict
except AttributeError:
pytest.skip("not defined using abi3 < 3.9")

d = ClassWithDict()
assert d.__dict__ == {}

d.foo = 42
Expand Down

0 comments on commit 744a283

Please sign in to comment.