pytest---断言

1,with.....pytest.raise

  发生指定的错误信息时,不中断测试(预期内的错误,不做用例失败处理)

  可以使用正则进行匹配

 

2,自定义断言的显示信息

  使用hook函数,pytest_assertrepr_compare

# 在conftest.py中写
def
pytest_assertrepr_compare(op, left, right): if isinstance(left, int) and isinstance(right, int) and op == "==": return [ "判断两个数字是否相等:", " vals: {} != {}".format(left, right), ]

 

  

posted @ 2020-07-31 16:32  myy2  阅读(155)  评论(0编辑  收藏  举报