3.6 测试函数的setup和teardown

测试函数的setup和teardown是指在测试脚本文件中没有定义测试类而直接定义的测试函数的setup和teardown,主要是指setup_function和teardown_function,setup_funxtion的作用是当前文件每个测试函数执行之前执行一次,而teardown_function则是在当前测试文件中每个测试函数执行结束后执行一次,它的作用跟测试类中的setup_method和teardown_method的作用类似

下面看一个例子(https://gitee.com/redrose2100/pytest-demo/blob/master/ch03/ex_011/test_demo.py),这里定义了两个测试函数test_01和test_02,同时定义了setup_function和teardown_fucntion

def setup_function():
    print("in setup_function ...")

def teardown_function():
    print("in teardown_function ...")

猜你喜欢

转载自blog.csdn.net/redrose2100/article/details/125270355
3.6