testbook
testbook copied to clipboard
Replace JSON serialization with cloudpickle and make reference semantics explicit.
trafficstars
See https://github.com/nteract/testbook/issues/138 for older discussion.
Copied from the changelog:
- replaced JSON serialization with cloudpickle. This allows extracting a much wider range of objects from the notebook subprocess.
- Reference semantics have changed.
- Old behavior of
tb.get(name)andtb[name]:- a reference would be returned for non-JSON-serializable objects.
- a value would be returned for JSON-serializable objects.
- Old behavior of
tb.ref(name)was identical totb.get(name). - However, now almost all objects are serializable and as a result, under
the old semantics, a reference would almost never be returned. Therefore,
when a reference is desired, we now require explicitly requesting a
reference. The new behavior of
tb.get(name)andtb[name]is to always return the deserialized object and to never return a reference. The new behavior oftb.ref(name)is to always return a reference.
- Old behavior of
I think this is a substantial improvement because:
- this PR allows serializing a much wider range of objects
- makes the API substantially clearer about when a reference will or will not be returned.
I understand that this is a mildly breaking change and adds a dependency and that must be weighed against the benefits. I would argue that the change is very worthwhile!
In my case, I wanted to be able to extract pandas DataFrames and various custom objects from a notebook under test.
Codecov Report
Merging #153 (0b65427) into main (62d7bd9) will increase coverage by
6.93%. The diff coverage is88.23%.
Additional details and impacted files
@@ Coverage Diff @@
## main #153 +/- ##
==========================================
+ Coverage 91.13% 98.07% +6.93%
==========================================
Files 7 8 +1
Lines 361 363 +2
==========================================
+ Hits 329 356 +27
+ Misses 32 7 -25