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)

    负重前行
  • 相关阅读:
    PHP PDO
    常用JavaScript字符串方法简述
    命名
    jquery远程班备忘
    html历史
    CSS3的翻转效果
    正则
    排序算法
    firebug的调试,console
    跨域
  • 原文地址:https://www.cnblogs.com/astride/p/12795202.html
Copyright © 2011-2022 走看看