前言
使用命令行执行pytest用例的时候,会在 terminal 终端打印整个用例的测试结果:
- .代表通过的用例
- F代表失败的用例
- E代表异常的用例
如果我们不喜欢这种报告结果,可以通过 pytest_report_teststatus 钩子函数改变测试报告的内容,接下来试试吧.改成√,把F改成x,这样更直观。
pytest_report_teststatus
pytest_report_teststatus(report, config): 返回各个测试阶段的result, 可以用when属性来区分不同阶段。
- when==‘setup’ 用例的前置操作
- when==‘call’ 用例的执行
- when==‘teardown’ 用例的后置操作
运行案例test_x.py
import pytest
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/
def test_01():
a = "hello"
b = "hello"
assert a == b
def test_02():
a = "hello"
b = "hello world"
assert a == b
def test_03():
a = "hello"
b = "hello world"
assert a in b
def test_04():
a &