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 ===========================