Skip to content

Commit f0d4475

Browse files
fix magic errors not causing failure (#78)
1 parent 8fa88df commit f0d4475

File tree

6 files changed

+190
-3
lines changed

6 files changed

+190
-3
lines changed

.github/workflows/test-publish-to-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
- run: poetry build
1515
- run: pip install 'pytest==7.1'
1616
- run: pip install dist/*gz --force-reinstall
17-
- run: pytest --nbmake tests/resources
17+
- run: pytest --nbmake tests/resources/mock.ipynb
1818
- run: pip install dist/*whl --force-reinstall
19-
- run: pytest --nbmake tests/resources
19+
- run: pytest --nbmake tests/resources/mock.ipynb
2020
- run: pip install twine==4.0.1
2121
- run: twine upload -r testpypi dist/* -u alex-treebeard-test -p ${{ secrets.TEST_PYPI_PASSWORD }}

poetry.lock

Lines changed: 104 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nbmake/nb_run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def execute(
6464
async def apply_mocks(
6565
cell: NotebookNode, cell_index: int, execute_reply: Dict[str, Any]
6666
):
67+
# https://github.com/treebeardtech/nbmake/issues/77
68+
if any(o["output_type"] == "error" for o in cell["outputs"]):
69+
execute_reply["content"]["status"] = "error"
70+
6771
if c.kc is None:
6872
raise Exception("there is no kernelclient")
6973
mocks: Dict[str, Any] = (

tests/resources/empty.ipynb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": []
9+
}
10+
],
11+
"metadata": {
12+
"language_info": {
13+
"name": "python"
14+
}
15+
},
16+
"nbformat": 4,
17+
"nbformat_minor": 2
18+
}

tests/resources/magic_error.ipynb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%matplotlib inline\n",
10+
"\n",
11+
"import matplotlib.pyplot as plt"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"fig, ax = plt.subplots(1, 1)\n",
21+
"ax.plot([0, 1, 2], [0, 1, 2])\n",
22+
"ax.set_xlabel(r\"$\\\\tau$\");"
23+
]
24+
}
25+
],
26+
"metadata": {
27+
"interpreter": {
28+
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
29+
},
30+
"kernelspec": {
31+
"display_name": "Python 3.10.4 64-bit",
32+
"language": "python",
33+
"name": "python3"
34+
},
35+
"language_info": {
36+
"codemirror_mode": {
37+
"name": "ipython",
38+
"version": 3
39+
},
40+
"file_extension": ".py",
41+
"mimetype": "text/x-python",
42+
"name": "python",
43+
"nbconvert_exporter": "python",
44+
"pygments_lexer": "ipython3",
45+
"version": "3.10.4"
46+
}
47+
},
48+
"nbformat": 4,
49+
"nbformat_minor": 2
50+
}

tests/test_nb_run.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ def test_when_mock_then_succeeds(self, testdir2: Never):
121121
run = NotebookRun(nb, 300)
122122
res: NotebookResult = run.execute()
123123
assert res.error == None
124+
125+
def test_when_magic_error_then_fails(self, testdir2: Never):
126+
nb = Path(__file__).parent / "resources" / "magic_error.ipynb"
127+
run = NotebookRun(nb, 300)
128+
res: NotebookResult = run.execute()
129+
assert res.error != None
130+
131+
def test_when_empty_then_succeeds(self, testdir2: Never):
132+
nb = Path(__file__).parent / "resources" / "empty.ipynb"
133+
run = NotebookRun(nb, 300)
134+
res: NotebookResult = run.execute()
135+
assert res.error is None

0 commit comments

Comments
 (0)