Python测试框架之pytest(三)测试装置介绍
一、测试装置介绍
setxxx 运行测试用例之前执行,具体需要看类型
tearxxx 运行测试用例之后执行,具体需要看类型
pytest有以下几种分类:
| 类型 | 规则 |
|---|---|
| setup_module/teardown_module | 全局模块级 |
| setup_class/teardown_class | 类级,只在类中前后运行一次 |
| setup_function/teardown_function | 函数级,在类外 |
| setup_method/teardown_method | 方法级,类中的每个方法执行前后 |
| setup/teardown | 在类中,运行在调用方法的前后 |
二、setup_module/teardown_module讲解
模块级别,只在该模块运行一次
举例:

二、setup_class/teardown_class讲解
类级别,只在类中前后运行一次。
注意一定要写在类中,否则是不生效的。
举例:

三、setup_function/teardown_function讲解
函数级,在类外。
如果测试用例是在类外的,则会生效;如果测试用例是在类内的,则不生效;
举例:

四、setup_method/teardown_method讲解
方法级,类中的每个方法执行前后

五、setup/teardown讲解
与setup_method/teardown_method的效果一致

浙公网安备 33010602011771号