建网站费用明细,c s网站开发模式,品牌推广案例,青岛网络优化哪家专业1. fixture 通常是对测试方法和测试函数#xff0c;测试类整个测试文件进行初始化或是还原测试环境
# 功能函数
def multiply(a, b):return a * b
# ------------ fixture---------------def setup_module(module):print(setup_module 在当前文件中所有测试用例之前测试类整个测试文件进行初始化或是还原测试环境
# 功能函数
def multiply(a, b):return a * b
# ------------ fixture---------------def setup_module(module):print(setup_module 在当前文件中所有测试用例之前)def teardown_module(module):print(teardown_module 在当前文件中所有测试用例之后)def setup_function(function):print(setup_function在每个测试函数之前执行)def teardown_function(function):print(setup_function在每个测试函数之后执行)def setup():print(setup---在每个测试函数之前------)def teardown():print(teardown----在每个测试函数之后可以作用于类方法-----)# ---------------测试用例-------------def test_mult_3_4():print(test_mult_3_4)assert multiply(3, 4) 12def test_mult_a_4():print(test_mult_a_3)assert multiply(a, 3) aaa 没有 setup/teardown? 2.支持Test 开头的测试类 # 功能函数
def multiply(a, b):return a * bclass TestMultiply:# fixturesclassmethoddef setup_class(cls):print(setup_class)classmethoddef teardown_class(cls):print(teardown_class)def setup_method(self, method):print(setup_method-----)def teardown_method(self, method):print(teardown_method--)def setup(self):print(setup-----)def teardown(self):print(teardown--)# 测试用例def test_numbers_5_6(self):print(test_numbers_5_6)assert multiply(5, 6) 30def test_strings_b_2(self):print(test_strings_b_2)assert multiply(b, 2) bb rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example\fixture
plugins: anyio-3.5.0
collected 2 items test_fixtures_02.py setup_class
setup_method-----
test_numbers_5_6
.teardown_method--
setup_method-----
test_strings_b_2
.teardown_method--
teardown_class