如何绕过“sys.exit()"在 python 鼻子测试中? [英] How to get around "sys.exit()" in python nosetest?
本文介绍了如何绕过“sys.exit()"在 python 鼻子测试中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎 python 鼻子测试在遇到sys.exit()"时会退出,并且模拟这个内置函数不起作用.感谢您的建议.
It seems that python nosetest will quit when encountered "sys.exit()", and mocking of this built-in doesn't work. Thanks for suggestions.
推荐答案
您可以尝试捕捉 SystemExit 异常.当有人调用 sys.exit()
时会引发它.
You can try catching the SystemExit exception. It is raised when someone calls sys.exit()
.
with self.assertRaises(SystemExit):
myFunctionThatSometimesCallsSysExit()
这篇关于如何绕过“sys.exit()"在 python 鼻子测试中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文