Coverage for Users / vladimirpavlov / PycharmProjects / parameterizable / tests / test_not_picklable.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-01 16:37 -0600

1import pickle 

2 

3from mixinforge import NotPicklableMixin 

4 

5import pytest 

6 

7def test_not_picklable(): 

8 npo = NotPicklableMixin() 

9 

10 # Test dunder methods directly 

11 with pytest.raises(TypeError): 

12 npo.__reduce__() 

13 with pytest.raises(TypeError): 

14 _ = npo.__getstate__() 

15 with pytest.raises(TypeError): 

16 npo.__setstate__({"key": "value"}) 

17 

18 # Test pickling via pickle.dumps(), which calls __reduce__() 

19 with pytest.raises(TypeError): 

20 pickle.dumps(npo) 

21 

22 # Test that a subclass is also not picklable 

23 class MyNotPicklableMixin(NotPicklableMixin): 

24 pass 

25 mnpo = MyNotPicklableMixin() 

26 with pytest.raises(TypeError): 

27 pickle.dumps(mnpo)