zoukankan      html  css  js  c++  java
  • pytest实例

    pytest 3.8.0

    运行 api>pytest test_pyexample.py

       #test_pyexample.py

    def add(x,y):

      return x+y

    def  test_add():

      assert add(1,2)==3

    def  test_add2():

      print("1 is 2")

    pytest-sugar查看测试用例的进度条

    pytest参数化

    a. 测试场景:

    • 测试登录成功,测试登录失败(账号错误/密码错误)
    • 创建多种账号,中文账号,英文账号

    b. copy多个代码或读入参数

    c. 一次性执行多个输入参数

    d. pytest.mark.parametrize

     #test_parameter.py

    import pytest

    @pytest.mark.parametrize("x,y",[(3+5,8),(2+5,7),(3*5,20)])

    def add(x,y):

      return x+y

    pytest 多个assert

    测试场景  一个测试用例中有多个数据需要比较

    一个个比较或者放到一个数据结构里面全量比较

    • 全量比较,无法知道哪个值不对
    • 一个个比较数值,第一个失败就退出

    运行 api>pytest test_pyexample_1.py

       #pytest test_pyexample_1.py

    import time

    def add(x,y):

      return x+y

    def  test_add():

      assert add(1,2)==3

    def  test_add2():

      print("1 is 2")

      time.sleep(3)

      assert add(1,2)==3

      assert add(12,21)==33

    安装pytest_assume 失败之后也能继续执行,断言用法为pytest.assume( add(12,21)==33)

    负重前行
  • 相关阅读:
    Zookeeper安装-单机版
    Centos 7 安装 Redis 5
    java利用dom4j将xml字符串转换为json
    计算机科学导论笔记-计算机组成
    计算机科学导论笔记-数据运算
    计算机科学导论笔记-数据存储
    计算机科学导论笔记-数字系统
    计算机科学导论笔记
    springmvc03
    springmvc02
  • 原文地址:https://www.cnblogs.com/astride/p/12795202.html
Copyright © 2011-2022 走看看