Skip to content

Commit

Permalink
Merge pull request jupyter#521 from mupdt982/feature/traceback-in-cel…
Browse files Browse the repository at this point in the history
…l-execution-error

Traceback in cell execution error
  • Loading branch information
takluyver authored Feb 15, 2017
2 parents a82b130 + 95b26da commit 59bd150
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions nbconvert/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CellExecutionError(ConversionException):
failures gracefully.
"""
def __init__(self, traceback):
super(CellExecutionError, self).__init__(traceback)
self.traceback = traceback

def __str__(self):
Expand Down
12 changes: 10 additions & 2 deletions nbconvert/preprocessors/tests/test_execute.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding=utf-8

"""
Module with tests for the execute preprocessor.
"""
Expand All @@ -12,12 +14,13 @@
import re

import nbformat
import sys

from .base import PreprocessorTestsBase
from ..execute import ExecutePreprocessor, CellExecutionError

from nbconvert.filters import strip_ansi
from nose.tools import assert_raises
from nose.tools import assert_raises, assert_in
from testpath import modified_env

addr_pat = re.compile(r'0x[0-9a-f]{7,9}')
Expand Down Expand Up @@ -184,7 +187,12 @@ def test_allow_errors(self):
res['metadata']['path'] = os.path.dirname(filename)
with assert_raises(CellExecutionError) as exc:
self.run_notebook(filename, dict(allow_errors=False), res)
self.assertIsInstance(str(exc), str)
self.assertIsInstance(str(exc.exception), str)
if sys.version_info >= (3, 0):
assert_in(u"# üñîçø∂é", str(exc.exception))
else:
assert_in(u"# üñîçø∂é".encode('utf8', 'replace'),
str(exc.exception))

def test_custom_kernel_manager(self):
from .fake_kernelmanager import FakeCustomKernelManager
Expand Down
11 changes: 11 additions & 0 deletions nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ def test_allow_errors(self):
with assert_raises(OSError):
self.nbconvert('--execute --to markdown --stdout notebook3*.ipynb')

def test_errors_print_traceback(self):
"""
Verify that the stderr output contains the traceback of the cell execution exception.
"""
with self.create_temp_cwd(['notebook3_with_errors.ipynb']):
_, error_output = self.nbconvert('--execute --to markdown --stdout notebook3_with_errors.ipynb',
ignore_return_code=True)
assert_in('print("Some text before the error")', error_output)
assert_in('raise RuntimeError("This is a deliberate exception")', error_output)
assert_in('RuntimeError: This is a deliberate exception', error_output)

def test_fenced_code_blocks_markdown(self):
"""
Verify that input cells use fenced code blocks with the language
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@

class ConversionException(Exception):
"""An exception raised by the conversion process."""

pass
pass

0 comments on commit 59bd150

Please sign in to comment.