Pytest项目_day08(setup、teardown前置后置操作)

setup

  • 模块级setup_module:运行于模块开始之前,生效一次

    • 一个py文件(测试文件)就是一个模块
  • 函数级setup_function:对于每条(不在类中的)函数用例生效,如果函数在类中,那么它在执行之前不会执行setup_function

    • 需要写在类之外
  • 类级setup_class:只在类开始前运行一次,写在在类中

  • 方法级setup_method:运行于方法之前,写在在类中

teardown

  • 模块级teardown_module:运行于模块结束之后,生效一次
    • 一个py文件(测试文件)就是一个模块
  • 函数级teardown_function:运行于每条函数用例结束之后,不在类中
  • 类级teardown_class:只在类结束后运行一次,在类中
  • 方法级teardown_method:运行于方法之后,在类中

快捷运行方法

  • 可以在测试文件中定义main,这样左键点击左侧的小箭头可以直接运行整个测试文件
相关推荐
我一定会有钱16 小时前
pytest基础
python·测试工具·测试用例·pytest
西游音月16 小时前
(6)pytest+Selenium自动化测试-测试用例编写
selenium·测试用例·pytest
兴趣使然黄小黄3 天前
【Pytest】Pytest框架快速入门
python·pytest
m0_632482504 天前
Jenkins + Pytest +allure接口自动化测试配置与操作
jenkins·集成测试·pytest·jenkins配置
李星星BruceL4 天前
Pytest第三章(参考指南1)
python·自动化·pytest
哎呀呦呵4 天前
pytest基本使用
python·pytest
Kristen_YXQDN4 天前
PyCharm 中 pytest 运行 python 测试文件报错:D:\Python_file\.venv\Scripts\python.exe: No module named pytest
运维·开发语言·python·pycharm·pytest
Low--Key4 天前
pytest框架快速入门
python·自动化·pytest
姜西西_4 天前
自动化测试框架pytest之fixture
android·java·pytest
测试开发Kevin4 天前
超级实用!汇总pytest中那些常用的参数
单元测试·pytest