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'])
相关推荐
互联网杂货铺12 小时前
python+pytest 接口自动化测试:参数关联
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
挽风8211 天前
Pytest自动化框架
自动化·pytest·模块测试
Xiaoshuang_Cao2 天前
pytest结合allure
pytest
摸鱼仙人~3 天前
结合unittest和pytest进行虚拟数据库测试
数据库·windows·pytest
江梦寻5 天前
如何使用 Python+Flask+win32print 实现简易网络打印服务
开发语言·后端·python·flask·pytest·web3.py·win32
qq_白羊座5 天前
pytest框架 核心知识的系统复习
pytest
@TangXin5 天前
单元测试-pytest框架实践
自动化测试·单元测试·pytest
evelol76 天前
【pytest框架源码分析四】pluggy源码分析之hook执行
自动化·pytest
云泽野7 天前
Pytest之parametrize参数化
android·python·pytest
evelol77 天前
【pytest框架源码分析三】pluggy源码分析之hook注册调用流程
自动化·pytest