Add py::pickle() adaptor for safer __getstate__/__setstate__ bindings
This is analogous to `py::init()` vs `__init__` + placement-new.
`py::pickle()` reuses most of the implementation details of `py::init()`.
diff --git a/tests/test_pickling.py b/tests/test_pickling.py
index 6cbcdf5..707d347 100644
--- a/tests/test_pickling.py
+++ b/tests/test_pickling.py
@@ -7,8 +7,10 @@
import pickle
-def test_roundtrip():
- p = m.Pickleable("test_value")
+@pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"])
+def test_roundtrip(cls_name):
+ cls = getattr(m, cls_name)
+ p = cls("test_value")
p.setExtra1(15)
p.setExtra2(48)
@@ -20,8 +22,10 @@
@pytest.unsupported_on_pypy
-def test_roundtrip_with_dict():
- p = m.PickleableWithDict("test_value")
+@pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"])
+def test_roundtrip_with_dict(cls_name):
+ cls = getattr(m, cls_name)
+ p = cls("test_value")
p.extra = 15
p.dynamic = "Attribute"