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), ]

  

原文地址:https://www.cnblogs.com/myy-py/p/13410497.html