print success messages for asserts in python

前端 未结 5 1053
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:14

    I would combine @dashingdw and @Reblochon Masque solution

    def my_assert(condition, fail_str, suc_str):
        assert condition, fail_str
        print suc_str   
    

    From my point of view this is less "dangerous" and you don't need to insert an additional print line every time.

提交回复
热议问题