diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index 3879689c5..78d2e8831 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -28,6 +28,7 @@ class CellExecutionError(ConversionException): failures gracefully. """ def __init__(self, traceback): + super(CellExecutionError, self).__init__(traceback) self.traceback = traceback def __str__(self): diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index 07022ca20..36da4392e 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -1,3 +1,5 @@ +# coding=utf-8 + """ Module with tests for the execute preprocessor. """ @@ -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}') @@ -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 diff --git a/nbconvert/tests/test_nbconvertapp.py b/nbconvert/tests/test_nbconvertapp.py index c11750832..4b87650bf 100644 --- a/nbconvert/tests/test_nbconvertapp.py +++ b/nbconvert/tests/test_nbconvertapp.py @@ -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 diff --git a/nbconvert/utils/exceptions.py b/nbconvert/utils/exceptions.py index 6a4e0e624..602e3f9d8 100644 --- a/nbconvert/utils/exceptions.py +++ b/nbconvert/utils/exceptions.py @@ -13,5 +13,4 @@ class ConversionException(Exception): """An exception raised by the conversion process.""" - - pass \ No newline at end of file + pass