我在python中使用assert。每次断言失败时,我都会得到一条失败消息,我会把它放在那里打印出来。我想知道当assert条件通过时是否有方法打印自定义成功消息?
我正在使用py.test框架。
例如:

assert self.clnt.stop_io()==1, "IO stop failed"

对于上面的断言,如果assert失败,我将得到消息“IO stop failed”,但是如果assert通过,我将寻找“IO stop succeeded”。像这样的:
 assert self.clnt.stop_io()==1, "IO stop failed", "IO stop succeeded"

最佳答案

是的,最简单的方法肯定是在断言下面打印:

assert self.clnt.stop_io()==1, "IO stop failed"
print("IO stop passed at location ==1")

关于python - 在python中打印断言的成功消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36834677/

10-11 22:38
查看更多