pytest入门三:setup、teardown

https://zhuanlan.zhihu.com/p/623447031

function对应类外的函数,每个函数调用一次

复制代码
import pytest
def setup_module():
    print('开始  module')


def teardown_module():
    print('结束 module')


def setup_function():
    print('开始 function')


def teardown_function():
    print('结束 function')


def test_one():
    print('这是one')


class TestDemo:

    def setup_class(self):
        print('开始 class')

    def teardown_class(self):
        print('结束 class')

    def setup_method(self):
        print('开始 method')

    def teardown_method(self):
        print('结束 method')

    def setup(self):
        print('开始 setup')

    def teardown(self):
        print('结束 setup')

    def test_two(self):
        print('这是two')
        assert 1 == 1

    def test_three(self):
        print('这是three')
        assert 1 > 0


if __name__ == "__main__":
    pytest.main(['-v', '-s','test.py'])
相关推荐
lifewange1 天前
pytest 找不到文件?直接在 pytest.ini 配置根目录 + 路径(最简单方案)
开发语言·python·pytest
老神在在0012 天前
保姆级教程:Pytest + Allure 接口自动化测试从 0 到 1 完整指南(含环境搭建、用例编写、报告生成、报错排坑全流程)
pycharm·pytest·测试
清水白石0082 天前
从手写初始化到 pytest fixture:让 Python 测试既干净、可复用,又能驾驭异步并发
开发语言·python·pytest
测试员周周2 天前
【AI测试数据及模型质量2】换一批测试数据,模型得分差20%——AI评测翻车的根子,90%在数据质量
人工智能·python·ui·单元测试·测试用例·集成测试·pytest
nbwenren10 天前
2026实测:Gemini 3.1 Pro 从需求文档到 pytest 测试用例一条龙教程
测试用例·pytest
我的xiaodoujiao10 天前
API 接口自动化测试详细图文教程学习系列16--项目实战演练3
python·学习·测试工具·pytest
我的xiaodoujiao10 天前
API 接口自动化测试详细图文教程学习系列15--项目实战演练2
python·学习·测试工具·pytest
技术钱12 天前
PyTest配置与API测试用例
servlet·测试用例·pytest
weixin_4196583113 天前
pytest 零基础入门实战指南
python·pycharm·pytest