zoukankan      html  css  js  c++  java
  • run测试用例函数写法.py

    import pytest
    import requests

    #定义预期结果:
    expect = {"title":"V2EX"}

    def test_case_01():
    response = requests.get(url='https://www.v2ex.com/api/site/info.json')
    #拿到json数据:
    print(response.json())
    if response.json()["title"] == expect["title"]:
    print("断言成功")
    assert 1
    else:
    print("断言失败")
    assert 0

    def test_case_02():
    response = requests.get(url='https://www.v2ex.com/api/site/info.json')
    #拿到json数据:
    print(response.json())
    if response.json()["title"] != expect["title"]:
    print("断言成功")
    assert 1
    else:
    print("断言失败")
    assert 0

    if __name__ == '__main__':
    #pytest框架自动收集这个脚本里面所有以test开头当成测试用例执行里面的代码
    pytest.main(["-s","run测试用例函数写法.py"])

    """
    结果:
    ============================= test session starts =============================
    platform win32(当前平台信息) -- Python 3.6.6(解释器版本), pytest-5.3.2(pytest版本), py-1.8.1, pluggy-0.13.1(以及其他版本)
    rootdir(根目录): D:s27day68
    collected 1 item(收集了一个用例)

    run.py {'title': 'V2EX', 'slogan': 'way to explore', 'description': '创意工作者们的社区', 'domain': 'www.v2ex.com'}
    断言成功
    .
    ================================== FAILURES(错误信息) ===================================
    ________________________________ test_case_02 _________________________________

    def test_case_02():
    response = requests.get(url='https://www.v2ex.com/api/site/info.json')
    #拿到json数据:
    print(response.json())
    if response.json()["title"] != expect["title"]:
    print("断言成功")
    assert 1
    else:
    print("断言失败")
    > assert 0
    E assert 0
    ============================== 1 passed in 1.01s(用例通过并耗时1秒) ==============================
    """
  • 相关阅读:
    Mongdb 简单增删改查
    mongdb的安装
    VO,DO,DTO,PO,POJO,EJB
    JavaScript是如何工作的:事件循环和异步编程的崛起+ 5种使用 async/await 更好地编码方式!
    判断DataTale中判断某个字段中包含某个数据
    查询表中某个字段的值出现次数大于1的数据
    判断对象数组中是否含有某个对象。
    C# datatable 重新排序
    jquery 验证大于0的整数
    jQuery 心跳请求
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12217536.html
Copyright © 2011-2022 走看看