1.fixture的teardown操作并不是独立的函数,用yield关键字呼唤teardown操作

2.scope="module"

1.fixture参数scope=”module”,module作用是整个.py文件都会生效( 整个文件只会执行一次),

用例调用时,参数写上函数名称就行

# 新建一个文件test_f1.py
# coding:utf-8
import pytest

@pytest.fixture(scope="module")
def open():
    print("打开浏览器,并且打开百度首页")

def test_s1(open):
    print("用例1:搜索python-1")

def test_s2(open):  # 不传login
    print("用例2:搜索python-2")

def test_s3(open):
    print("用例3:搜索python-3")

if __name__ == "__main__":
    pytest.main(["-s", "test_f1.py"])

运行结果:

============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: D:\, inifile:
collected 3 items

..\..\..\..\..\..\test_f1.py 打开浏览器,并且打开百度首页
用例1:搜索python-1
.用例2:搜索python-2
.用例3:搜索python-3
.

========================== 3 passed in 0.01 seconds ===========================
View Code

相关文章:

  • 2021-10-30
  • 2021-12-23
  • 2022-01-06
  • 2021-11-04
  • 2021-11-20
  • 2021-11-29
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2021-10-08
  • 2021-08-11
  • 2021-10-18
  • 2022-12-23
  • 2021-11-02
  • 2021-08-24
相关资源
相似解决方案