Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag magic usage errors as failures #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/nbmake/nb_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (%<command>) usage error",
trace="",
failing_cell_index=-1,
)
except CellTimeoutError as err:
trace = err.args[0]
error = NotebookError(
Expand Down
46 changes: 46 additions & 0 deletions tests/resources/usageerror.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions tests/test_nb_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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