diff --git a/direct/src/stdpy/pickle.py b/direct/src/stdpy/pickle.py index 60d2b7d92f..1c59888958 100644 --- a/direct/src/stdpy/pickle.py +++ b/direct/src/stdpy/pickle.py @@ -33,6 +33,8 @@ else: # with the local pickle.py. pickle = __import__('pickle') +PicklingError = pickle.PicklingError + if sys.version_info >= (3, 0): BasePickler = pickle._Pickler BaseUnpickler = pickle._Unpickler diff --git a/tests/stdpy/test_pickle.py b/tests/stdpy/test_pickle.py index 303c5559c1..3e8a7dcd25 100644 --- a/tests/stdpy/test_pickle.py +++ b/tests/stdpy/test_pickle.py @@ -1,4 +1,5 @@ -from direct.stdpy.pickle import dumps, loads +from direct.stdpy.pickle import dumps, loads, PicklingError +import pytest def test_reduce_persist(): @@ -9,3 +10,12 @@ def test_reduce_persist(): parent2, child2 = loads(dumps([parent, child])) assert tuple(parent2.children) == (child2,) + + +def test_pickle_error(): + class ErroneousPickleable(object): + def __reduce__(self): + return 12345 + + with pytest.raises(PicklingError): + dumps(ErroneousPickleable())