码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Pytest插件


    官方文档:API Reference — pytest documentation

    BaseReport 定义Case结果输出

    1. >>> from _pytest.reports import TestReport
    2. >>> test = TestReport(1,1,1,'pass','','running')
    3. >>> print(dir(test))
    4. ['__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__test__', '__weakref__', '_from_json', '_get_verbose_word', '_to_json', 'caplog', 'capstderr', 'capstdout', 'count_towards_summary', 'duration', 'failed', 'from_item_and_call', 'fspath', 'get_sections', 'head_line', 'keywords', 'location', 'longrepr', 'longreprtext', 'nodeid', 'outcome', 'passed', 'sections', 'skipped', 'toterminal', 'user_properties', 'when']

    pluggy — pluggy 1.3.1.dev11+g46fec3f documentationicon-default.png?t=N7T8https://pluggy.readthedocs.io/en/latest/index.html#hookwrappers

    1. # pytest插件 https://www.osgeo.cn/pytest/writing_plugins.html
    2. import pytest
    3. @pytest.hookimpl(hookwrapper=True, tryfirst=True)
    4. def pytest_runtest_makereport(item, call):
    5. print('-------------------------------')
    6. # 获取常规的钩子方法的调用结果,返回一个result对象
    7. out = yield
    8. print('用例的执行结果', out)
    9. # 获取调用结果的测试报告,返回一个report对象,report对象的属性
    10. # 包括when(setup, call, teardown三个值)、nodeid(测试用例的名字)、
    11. # outcome(用例执行的结果 passed, failed)
    12. report = out.get_result()
    13. print('测试报告: %s' % report)
    14. print('步骤:%s' % report.when)
    15. print('nodeid: %s' % report.nodeid)
    16. # 打印函数注释信息
    17. print('description: %s' % str(item.function.__doc__))
    18. print('运行结果: %s' % report.outcome)

    case运行不同步骤,重写pytest处理结果

    1. print('步骤:%s' % report.when)
    2. if when == "call":
    3. custom.running_test(item, call, report)
    4. if when == 'setup':
    5. custom.before_test(item, call, report)
    6. if when == 'teardown':
    7. custom.after_test(item, call, report)

    获取case运行时失败信息

    1. excinfo = call.excinfo
    2. trace_info = traceback.format_exception(excinfo.type, excinfo.value, excinfo.tb )

    获取case运行时失败信息

    1. report = out.get_result()
    2. print('测试报告Case日志: %s' % report.caplog())
    3. print('测试报告Case stderr: %s' % report.capstderr())
    4. print('测试报告Case stdout: %s' % report.capstdout())

  • 相关阅读:
    Java也能做OCR!SpringBoot 整合 Tess4J 实现图片文字识别
    Cadence Allegro PCB设计88问解析(十五) 之 Allegro中如何替换过孔类型
    1.1 Metasploit 工具简介
    原型设计软件,异地办公提升效率
    Java——》MESI
    使用Selenium进行Web自动化操作
    猿创征文|GaussDB(for openGauss):基于 GaussDB 迁移、智能管理构建应用解决方案
    Linux虚拟机克隆之后使用ip addr无法获取ip地址
    服务器数据恢复-Xen server虚拟机数据恢复案例
    Mybatis-Plus入门实践
  • 原文地址:https://blog.csdn.net/Kingairy/article/details/134290916
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号