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'])
相关推荐
思则变8 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
思则变1 天前
[Pytest][Part 3]检测python package状态
pytest
cooldream200915 天前
pytest 框架详解与实战指南
pytest·测试
慕城南风15 天前
【pytest进阶】Pytest之conftest详解
pytest
编程小白gogogo16 天前
AI自动化测试速成(Pytest框架)
pytest
慕城南风16 天前
【pytest进阶】pytest详解及进阶使用
linux·服务器·pytest
Tom Boom23 天前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
不要一直敲门24 天前
初学 pytest 记录
pytest
测试界清流25 天前
Selenium4+Pytest自动化测试框架
selenium·测试工具·pytest