pytest 给我们开放了大量的 hook 函数,可以编写插件
pytest 可以识别到三种插件:
内置插件:从 pytest 内部 _pytest 目录加载的插件
外部插件:通过 pip 安装的插件(比如: pip install pytest-ordering )。
conftest.py 插件:测试目录中的 conftest.py 加载
钩子函数:
pytest hook 链接: https://docs.pytest.org/en/stable/reference.html?#hooks
pytest hook 函数也叫钩子函数,是pytest 框架开发者为用户预留的一些函,pytest 提供了大量的钩子函数,可以在用例的不同生命周期自动调用
使用:
执行完测试用例后,需要对结果进行汇总,用例总数,失败用例数,成功用例数等。
pytest有自带的一个钩子函数:pytest_terminal_summary
# conftest.py
def pytest_terminal_summary(terminalreporter, exitstatus, config):
"""
:param terminalreporter: 报告汇总
:param exitstatus: 退出状态
:param config: 全局 Config 对象, 等同于 request.config
:return:
exitstatus:
0 -- 用例全部通过
1 -- 有用例失败
2 -- 收集用i就失败了,还没执行
3 -- 其他报错
4 -- 其他报错
5 -- 收集到0条用例
"""
print(f'退出状态:{
exitstatus}')
# 获取环境地址
base_url = config.option.base_url
print(f'获取到的base_url: {
base_url}')
total = terminalreporter._numcollected
if exitstatus in [0, 1]:
passed = len([i for i in terminalreporter.stats.get('passed', [

最低0.47元/天 解锁文章
1647

被折叠的 条评论
为什么被折叠?



