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'])
相关推荐
独断万古他化3 小时前
Python+Pytest 接口自动化测试实战 —— 抽奖系统接口测试框架设计与实现
python·pytest·接口自动化·测试·allure·yaml·json schema
小陈的进阶之路10 小时前
Selenium 常用操作 API
python·自动化·pytest
紫丁香11 小时前
pytest_自动化测试5
python·功能测试·单元测试·集成测试·pytest
姚青&11 小时前
Pytest fixture 参数化(params 参数)
开发语言·python·pytest
小张贼嚣张12 小时前
Pytest 核心特性与技术优势
pytest
姚青&13 小时前
Pytest 配置文件
pytest
姚青&20 小时前
Pytest 插件
pytest
姚青&1 天前
Pytest 测试用例生命周期管理-yield
测试用例·pytest
紫丁香1 天前
pytest_自动化测试3
开发语言·python·功能测试·单元测试·集成测试·pytest
小罗和阿泽1 天前
接口测试系列 接口自动化测试 pytest框架(二)
pytest