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)

    负重前行
  • 相关阅读:
    P1119 灾后重建
    P1453 城市环路
    21.10.28模拟 C
    21.10.28模拟 String Coloring AGC26 C
    P1155 [NOIP2008 提高组] 双栈排序
    21.10.27模拟 solve
    21.10.27模拟 P4157 [SCOI2006]整数划分
    P2168 [NOI2015] 荷马史诗
    P3052 [USACO12MAR]Cows in a Skyscraper G
    P2533 [AHOI2012]信号塔 P1742 最小圆覆盖
  • 原文地址:https://www.cnblogs.com/astride/p/12795202.html
Copyright © 2011-2022 走看看