pytest实例2

pytest_rerunfails

测试场景:

  在web/app自动化测试中,经常出现超时导致测试失败

加成等待时间,或者重新执行

 

运行 pytest -sq -reruns 7   文件名               (7代表再次运行的最多次数,sq代表日志输出)

   #test_pyexample.py

def add(x,y):

  return x+y

def  test_add():

  assert add(1,2)==3

def  test_add2():

  random_value = random.randint(2,5)

  print("random_value:"+str(random_value))

  assert random_value == 3

 

Pytest -ordering

测试场景

  • 在web测试中,上下测试用例页面切换有依赖关系
  • 在修改信息的页面中,依赖于前面用例已经创建好的信息,比如修改账号信息,依赖于已经创建好的数据

# test_order.py

import time

import pytest

value = 0

@pytest.mark.run(order=1)

def  test_add2():

  print("1 is 2")

  time.sleep(2)

  assert value==10

@pytest.mark.run(order=1)

def test_add():

  global value

  value = 10

  assert value==10

posted on 2020-04-30 14:39  菲菲菲非常可爱的小白兔  阅读(115)  评论(0编辑  收藏  举报