目录
模块级(setup_module/teardown_module)
函数级(setup_function/teardown_function)
用例运行级别
-
模块级(setup_module/teardown_module):开始于模块始末,全局的
-
函数级(setup_function/teardown_function):只对函数用例生效(不在类中)
-
类级(setup_class/teardown_class):只在类中前后运行一次(在类中)
-
方法级(setup_method/teardown_method):开始于方法始末(在类中)
-
类里面的(setup/teardown):运行在调用方法的前后
模块级(setup_module/teardown_module)
setup_module:所有用例开始前只执行一次
teardown_module:所有用例结束后只执行一次
示例1:
#coding:utf-8
#模块级(setup_module/teardown_module)
import pytest
def setup_module():
print("setup_module:所有用例开始前只执行一次")
print("----------------------------")
def teardown_module():
print("-----------------------------")
print("teardown_module:所有用例结束后只执行一次")
def setup_function():
print("setup_function:每个用例开始前执行")
def teardown_function():
print("teardown_function:每个用例结束后执行")
def test_1():
print("正在执行test_1。。。。。。")
a="hello"
#assert断言
asse