Jupyter笔记本中的Surface%%bash错误

Jupyter笔记本中的Surface%%bash错误,bash,jupyter,jupyter-notebook,Bash,Jupyter,Jupyter Notebook,我有一些Jupyter笔记本,我想作为自动测试运行。我可以从命令行运行jupyter nbconvert--execute Test.ipynb(有更好的方法吗?),如果任何Python单元引发异常,它将引发异常。我还可以使用python API,它看起来像这样: import nbformat from nbconvert.preprocessors import ExecutePreprocessor from nbconvert.preprocessors.execute import C

我有一些Jupyter笔记本,我想作为自动测试运行。我可以从命令行运行jupyter nbconvert--execute Test.ipynb(有更好的方法吗?),如果任何Python单元引发异常,它将引发异常。我还可以使用python API,它看起来像这样:

import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert.preprocessors.execute import CellExecutionError

with open(notebook_filename, 'r') as f:
    nb = nbformat.read(f, as_version=4)

ep = ExecutePreprocessor(kernel_name='python3')
try:
    out = ep.preprocess(nb, {'metadata': {'path': './'}})
except CellExecutionError as e:
    raise Exception('Python notebook %s failed with error: %s' % (notebook_filename, e))
但是,如果我的笔记本包含bash单元格,例如

%%bash 
python test.py
…如果在子流程中运行的python脚本引发异常,则此异常不会显示在命令行中。可以肯定的是,异常由笔记本记录并显示,例如

Traceback (most recent call last):   File "test.py", line 1, in <module>
    raise Exception('wat') Exception: wat

如何让Jupyter显示这些错误?

为什么不将笔记本另存为python脚本并运行脚本
jupyter nbconvert——编写Test.ipynb
脚本,然后编写python Test.py@kikocorreoso脚本,这也不会引发异常。程序打印异常,并成功退出。
$ jupyter nbconvert --execute notebooks/Test.ipynb
[NbConvertApp] Converting notebook notebooks/Test.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
[NbConvertApp] Writing 249850 bytes to notebooks/Test.html