Skip to content

Commit

Permalink
fix internal error (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-treebeard authored Feb 12, 2023
1 parent 417688b commit d9db1b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nbmake/pytest_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import nbformat
import pytest
from _pytest._code.code import ReprFileLocation, TerminalRepr, TerminalWriter
from nbformat.reader import NotJSONError
from pygments import highlight
from pygments.formatters import TerminalTrueColorFormatter
from pygments.lexers import Python3TracebackLexer
Expand Down Expand Up @@ -75,7 +76,14 @@ def create_internal_err() -> Any:
"NBMAKE INTERNAL ERROR",
)

if type(excinfo.value) != NotebookFailedException:
exc_type = type(excinfo.value)

if exc_type is NotJSONError:
return NbMakeFailureRepr(
"This file is not a valid json document", excinfo.value.args[0]
)

if exc_type != NotebookFailedException:
return create_internal_err()

res: NotebookResult = excinfo.value.args[0]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,15 @@ def test_when_no_import_errs_then_pass(pytester: Pytester, testdir2: Never):
hook_recorder = pytester.inline_run("--nbmake", "--nbmake-find-import-errors")

assert hook_recorder.ret == ExitCode.OK


def test_when_not_json_then_correct_err_msg(pytester: Pytester, testdir2: Never):

(Path(pytester.path) / "a.ipynb").write_text("invalid json")

hook_recorder = pytester.inline_run("--nbmake")

longrepr = hook_recorder.listoutcomes()[2][0].longrepr
assert longrepr is not None
assert "NBMAKE INTERNAL ERROR" not in longrepr.term
assert "json" in longrepr.term

0 comments on commit d9db1b0

Please sign in to comment.