在测试中检查 CLI 的退出代码 [英] Checking the exit code of a CLI in a test
本文介绍了在测试中检查 CLI 的退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为命令行工具编写自动化测试.本质上,我想使用各种选项调用 CLI 并测试退出代码和/或输出.
I am writing automated tests for a command line tool. Essentially, I want to invoke the CLI with various options and test the exit code and/or output.
我的测试如下:
from mymodule.cli_tool import main
def test_args(capfd):
with pytest.raises(SystemExit) as e:
main(args=['--junk_option'])
# check the exit code to make sure it is non-zero
???
如何查看退出代码?
推荐答案
你需要检查value.code
,像这样:
assert e.value.code != 0
这篇关于在测试中检查 CLI 的退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文