上一篇讲到fixture
通过scope
参数控制setup
级别,既然有setup
作为用例之前前的操作,用例执行完之后那肯定也有teardown
操作。
这里用到fixture
的teardown
操作并不是独立的函数,用yield
关键字呼唤teardown
操作;
scope=“module”
1.fixture
参数scope="module"
,module
作用是整个.py文件都会生效,用例调用时,参数写上函数名称就行;
import pytest
@pytest.fixture(scope="module")
def login():
print("=================开始登陆login====================")
def test_01(login):
print("====================test_01================")
def test_02():
print("====================test_02================")
def test_03(login):
print("====================test_03================")
if __name__ == "__main__":
pytest.main(["-s","test_fix3.py"])
运行结果:
test_fix3.py::test_01 =================开始登陆login====================
PASSED [ 33%]====================test_01================
test_fix3.py::test_02 PASSED [ 66%]====================test_02================
test_fix3.py::test_03 PASSED [100%]==