我正在运行一个 python cli 工具 Papermill。我正在运行 jupyter 笔记本,并希望能够在运行笔记本时检测到 assertionErrors。当我从 bash 脚本运行 papermill 时,我总是得到一个 0 退出代码,即使笔记本中存在 python 错误也是如此。
我找到了检测退出代码的方法,但python错误没有抛出任何代码
例如:在我的 nbTest.sh 中,我正在运行笔记本并查找错误
papermill python_notebooks/testing/$d python_notebooks/testing/results/$d.results.ipynb || True
if [ $? -eq 0 ]
then
echo "Successfully executed script"
else
# Redirect stdout from echo command to stderr.
echo "Script exited with error."
fi
done
作为输出,我得到:
.
.
.
Input Notebook: python_notebooks/testing/paperTest.ipynb
Output Notebook: python_notebooks/testing/results/paperTest.ipynb.results.ipynb
83%|████████▎ | 5/6 [00:00<00:00, 1.97it/s]
Traceback (most recent call last):
...
---------------------------------------------------------------------------
Exception encountered at "In [5]":
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-5-d941c6663321> in <module>()
----> 1 assert passed == False
AssertionError:
Successfully executed script
我希望退出代码为 1,但未处理 python 故障