nbval
nbval copied to clipboard
Traceback: Missing output fields from running code: {'image/svg+xml'}
Hi there,
I encountered failed tests of my notebook for cells that produce plots. I have been getting an error:
Traceback: Missing output fields from running code: {'image/svg+xml'}
What is the best way to avoid this type of errors ?
Seems like your notebook file has an image/svg+xml output that is not showing up when nbval runs the notebook.
In my case it was:
Traceback: Missing output fields from running code: {'stderr'}
because a pair of stderr.write calls in one cell were ending up as separate outputs when run via Papermill, but were merged into one output when run interactively or via py.test --nbval.
Here's the place where the message originates: https://github.com/computationalmodelling/nbval/blob/d7bc34893a9251fbfd4b270347197619c32fe6ea/nbval/plugin.py#L479-L486
It is triggered when the re-run cell's outputs don't match the notebook file on disk.
The pytest/nbval output specifices which code cell index the error occurred at. Here's an easy way to inspect a given cell (including outputs / metadata):
cell_idx=6
jq '[.cells[] | select(.cell_type == "code")]'"[$cell_idx]" notebook.ipynb