• pytest + yaml 框架 -56. 输出日志优化+allure报告优化


    前言

    v1.4.8 版本优化接口请求和响应输出日志,生成的allure报告也按步骤优化request和response详情日志

    优化日志

    用例

    test_log1:
    -
      name: log1
      request:
        url: http://127.0.0.1:8000/api/test/demo
        method: GET
      validate:
        - eq: [status_code, 200]
        - eq: ['"code": (.+?),', '0']
        - eq: ['"msg": "(.+?)"', '成功success!']
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    控制台日志优化

    a0_log/test_log.yml::test_re2
    ----------------------------------------------------- live log call ------------------------------------------------------
    2023-09-25 18:21:01 [INFO]: 执行文件-> test_log.yml
    2023-09-25 18:21:01 [INFO]: base_url-> http://127.0.0.1:8000
    2023-09-25 18:21:01 [INFO]: config variables-> {}
    2023-09-25 18:21:01 [INFO]: 运行用例-> test_re2
    2023-09-25 18:21:01 [INFO]: yml raw  -->: {'url': 'http://127.0.0.1:8000/api/test/demo', 'method': 'GET'}
    2023-09-25 18:21:01 [INFO]: ------  request info   ------
    GET http://127.0.0.1:8000/api/test/demo
    headers: {
        "User-Agent": "python-requests/2.31.0",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive"
    }
    
    2023-09-25 18:21:11 [INFO]: ------  response info   ------
    url: http://127.0.0.1:8000/api/test/demo
    status_code: 200 OK
    headers: {
        "Date": "Mon, 25 Sep 2023 10:21:09 GMT",
        "Server": "WSGIServer/0.2 CPython/3.6.8",
        "Content-Type": "application/json",
        "X-Frame-Options": "SAMEORIGIN",
        "Content-Length": "260"
    }
    cookies: {}
    body: {
        "code": 0,
        "msg": "成功success!",
        "data": [
            {
                "age": 20,
                "create_time": "2019-09-15",
                "id": 1,
                "mail": "283340479@qq.com",
                "name": "yoyo",
                "sex": "M"
            },
            {
                "age": 21,
                "create_time": "2019-09-16",
                "id": 2,
                "mail": "123445@qq.com",
                "name": "yoyo111",
                "sex": "M"
            }
        ]
    }
    
    2023-09-25 18:21:11 [INFO]: validate 校验内容-> [{'eq': ['status_code', 200]}, {'eq': ['"code": (.+?),', '0']}, {'eq': ['"m
    sg": "(.+?)"', '成功success!']}]
    2023-09-25 18:21:11 [INFO]: validate 校验结果-> eq: [200, 200]
    2023-09-25 18:21:11 [INFO]: validate 校验结果-> eq: [0, 0]
    2023-09-25 18:21:11 [INFO]: validate 校验结果-> eq: [成功success!, 成功success!]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55

    allure 报告展示

    生成allure报告

    pytest --alluredir ./report
    allure serve ./report
    
    • 1
    • 2


    网易云完整视频课程https://study.163.com/course/courseMain.htm?courseId=1213419817&share=2&shareId=480000002230338
    报名咨询wx:283340479 (已报名的同学学习过程中有问题,都可以协助解决)

  • 相关阅读:
    OpenCV自学笔记十二:形态操作(二)
    SpringMVC如何实现重定向和转发呢?
    Python学习笔记合集(Matplotlib总结)
    魔法猪系统重装大师怎么使用
    淘宝API接口,获得淘宝app商品详情原数据(Onebound数据)
    [MySql]初识数据库与常见基本操作
    前端工作总结100-vue中name错误
    【C++学习笔记】静态多态与动态多态
    家用电脑做服务器,本地服务器搭建,公网IP申请,路由器改桥接模式,拨号上网
    关于架构的认知
  • 原文地址:https://blog.csdn.net/qq_27371025/article/details/133741805