print success messages for asserts in python

前端 未结 5 1048
Happy的楠姐
Happy的楠姐 2020-12-19 14:04

I am using assert in python. Every time an assert fails I get the failure message which I would have put there to be printed. I was wondering if there is a way to print a cu

5条回答
  •  一整个雨季
    2020-12-19 14:30

    Write a simple helper function:

    def myfunc(msg='assert OK'):
        print msg
        return True
    

    Include that in the condition on the right-side, after an and:

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

提交回复
热议问题