diff --git a/src/nbmake/nb_run.py b/src/nbmake/nb_run.py index 697e559..80062ab 100644 --- a/src/nbmake/nb_run.py +++ b/src/nbmake/nb_run.py @@ -86,7 +86,11 @@ async def apply_mocks( c.execute(cwd=self.filename.parent) except CellExecutionError: - error = self._get_error(nb) + error = self._get_error(nb) or NotebookError( + summary="An untraced error occurred. This likely was a cell magic (%) usage error", + trace="", + failing_cell_index=-1, + ) except CellTimeoutError as err: trace = err.args[0] error = NotebookError( diff --git a/tests/resources/usageerror.ipynb b/tests/resources/usageerror.ipynb new file mode 100644 index 0000000..9aabf9c --- /dev/null +++ b/tests/resources/usageerror.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%fls u908" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(4)" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" + }, + "kernelspec": { + "display_name": "Python 3.8.9 64-bit", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/test_nb_run.py b/tests/test_nb_run.py index 9d7f7ed..ef42e32 100644 --- a/tests/test_nb_run.py +++ b/tests/test_nb_run.py @@ -133,3 +133,9 @@ def test_when_empty_then_succeeds(self, testdir2: Never): run = NotebookRun(nb, 300) res: NotebookResult = run.execute() assert res.error is None + + def test_when_usage_error_then_fails(self, testdir2: Never): + nb = Path(__file__).parent / "resources" / "usageerror.ipynb" + run = NotebookRun(nb, 300) + res: NotebookResult = run.execute() + assert res.error != None