diff --git a/papermill/tests/notebooks/line_magic_error.ipynb b/papermill/tests/notebooks/line_magic_error.ipynb new file mode 100644 index 00000000..1751eab5 --- /dev/null +++ b/papermill/tests/notebooks/line_magic_error.ipynb @@ -0,0 +1,43 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%undefined-line-magic" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Cell should not execute.\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/papermill/tests/test_execute.py b/papermill/tests/test_execute.py index 46b59524..705d418c 100644 --- a/papermill/tests/test_execute.py +++ b/papermill/tests/test_execute.py @@ -327,6 +327,19 @@ def test_system_exit(self): self.assertEqual(nb.cells[1].outputs[0].evalue, '') self.assertEqual(nb.cells[2].execution_count, None) + def test_line_magic_error(self): + notebook_name = 'line_magic_error.ipynb' + result_path = os.path.join(self.test_dir, f'output_{notebook_name}') + with self.assertRaises(PapermillExecutionError): + execute_notebook(get_notebook_path(notebook_name), result_path) + nb = load_notebook_node(result_path) + self.assertEqual(nb.cells[0].cell_type, "markdown") + self.assertRegex(nb.cells[0].source, r'^$') + self.assertEqual(nb.cells[0].metadata["tags"], ["papermill-error-cell-tag"]) + self.assertEqual(nb.cells[2].cell_type, "code") + self.assertEqual(nb.cells[2].execution_count, 1) + self.assertEqual(nb.cells[3].execution_count, None) + class TestNotebookValidation(unittest.TestCase): def setUp(self):