print success messages for asserts in python

前端 未结 5 1050
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条回答
  •  梦毁少年i
    2020-12-19 14:32

    If you are really feeling adventurous, you can just write your own extensible assert wrapper - with which you can count the number of asserts failed or add functionality like testing in quiet or verbose modes eg:

    def assert(condition, fail_str, suc_str):
         if condition:
              print fail_str
         else:
              num_tests_passed = num_tests_passed + 1
              if verbose_enabled:
                  print suc_str
    

提交回复
热议问题