为了账号安全,请及时绑定邮箱和手机立即绑定

从 shell 脚本中获取 pytest 退出代码

从 shell 脚本中获取 pytest 退出代码

幕布斯6054654 2022-01-05 13:12:20
我正在从 shell 脚本运行 pytest 测试。脚本中的相关行类似于:pytest pytest_tests --param=$my_param根据 pytest 文档,“运行 pytest 可能会导致六个不同的退出代码”(0-5)。我的问题是如何从脚本中获取此退出代码?我试过类似的东西exit_code = pytest pytest_tests --param=$my_param echo $exit_code但我得到了这个:exit_code: command not found我怎么才能得到它?或者有没有更好的方法在shell脚本中获得pytest结果?
查看完整描述

1 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

命令运行后,它的退出代码应该可以通过$?变量获得。尝试这样的事情:

pytest pytest_tests --param=$my_param
echo Pytest exited $?

这适用于 Bash,也应该适用于常规的shBourne shell 和 zsh。

如果您需要将此分配给另一个变量,请使用

my_var=$?

请注意缺少空格。


查看完整回答
反对 回复 2022-01-05
  • 1 回答
  • 0 关注
  • 165 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号