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'])
相关推荐
兴趣使然黄小黄1 天前
【Pytest】使用Allure生成企业级测试报告
python·pytest
少云清2 天前
【接口测试】4_代码实现 _pytest框架
pytest·接口测试
屋顶那猫2 天前
使用pyinstaller打包pytest项目
python·pytest
zyx没烦恼3 天前
pytest框架
pytest
兴趣使然黄小黄5 天前
【Pytest】Pytest常用的第三方插件
python·pytest
我的xiaodoujiao5 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 34--基础知识 9--文件上传功能
前端·python·测试工具·ui·pytest
我一定会有钱5 天前
pytest测试框架基础
python·单元测试·自动化·pytest
我的xiaodoujiao5 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 35--二次封装MySQL数据库连接操作
python·学习·测试工具·pytest
给你一页白纸6 天前
Pytest 测试用例自动生成:接口自动化进阶实践
python·pytest·接口自动化
工会主席-阿冰6 天前
使用pytest-selenium插件,ui自动化示例
selenium·pytest