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'])
相关推荐
天才测试猿10 小时前
接口自动化测试之pytest接口关联框架封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
not coder1 天前
Pytest Fixture 详解
数据库·pytest
not coder2 天前
pytest 常见问题解答 (FAQ)
开发语言·python·pytest
程序员的世界你不懂2 天前
(1)pytest简介和环境准备
pytest
not coder2 天前
Pytest Fixture 是什么?
数据库·oracle·pytest
Tester_孙大壮2 天前
pytest中的元类思想与实战应用
pytest
<花开花落>2 天前
pytest 中 fixture 与类继承交互导致的问题
python·pytest
Julyyyyyyyyyyy2 天前
【软件测试】测试框架(unittest/pytest)
测试工具·pycharm·自动化·pytest
not coder2 天前
pytest 常用命令参数
pytest
not coder7 天前
Pytest 是什么
数据库·pytest