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秒) ==============================
    """
  • 相关阅读:
    【WPF】操作RichTextBox(取值、赋值、清空、滚动条自动滚动实例、文本自动滚动实例)
    系统初始化 服务列表
    多个filter如何决定调用顺序
    IE浏览器 查看Form对象
    java try_catch 分析
    关于ClassLoader 和Class的俩个记录
    lis分析之一一批处理(任务)如何连接数据库的
    document.all("div).style.display = "none"与 等于""的区别
    Mybatis Util包
    Spring创建bean对象的三种方式
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12217536.html
Copyright © 2011-2022 走看看