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'])
相关推荐
程序员的世界你不懂2 小时前
Pytest-mark使用详解(跳过、标记、参数 化)
pytest
fish_study_csdn2 天前
pytest 技术总结
开发语言·python·pytest
难以怀瑾3 天前
pytest心得体会
pytest
慌糖4 天前
[特殊字符]️ 基于Pytest的自动化测试框架架构解析
pytest
旦莫5 天前
Pytest教程:为什么Pytest要用插件模式?
python·单元测试·自动化·pytest
三次握手四次挥手6 天前
基于Python+Pytest实现自动化测试(全栈实战指南)
开发语言·python·自动化·k8s·apache·pytest·代码规范
世界的尽头在哪里7 天前
python测试框架之pytest
开发语言·python·测试工具·单元测试·pytest
胆大的8 天前
怎样才能设计好的自动化测试用例
自动化·测试用例·pytest
雨中夜归人11 天前
自动化测试工具playwright中文文档-------14.Chrome 插件
python·测试工具·自动化·pytest·playwright