fixture+yield用法
import pytest class TestCase: def setup_class(self): print("setup_class:所有用例执行之前") def setup_method(self): print("setup_method: 每个用例开始前执行") def teardown_method(self): print("teardown_method: 每个用例结束后执行") def teardown_class(self): print("teardown_class:所有用例执行之后") @pytest.fixture(scope="class") def fixture_class(self): """class级别""" print("fixture_class:执行class级别装饰器") yield print("fixture_class:恢复class级别设置") @pytest.fixture(scope="function") def fixture_function(self): """用例级别""" print("fixture_function:执行用例级别装饰器") yield print("fixture_function:恢复用例级别设置") def test_A(self, fixture_function): print("用例A") assert True def test_B(self): print("用例B") assert True def test_C(self, fixture_function, fixture_class): print("用例C") assert True def test_D(self): print("用例C") assert True
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/18037380