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'])
相关推荐
丿罗小黑1 天前
Pytest项目_day15(yaml)
pytest
丿罗小黑1 天前
Pytest项目_day16(yaml和parametrize结合)
pytest
代码小念2 天前
Pytest+selenium UI自动化测试实战实例(超详细)
selenium·ui·pytest
丿罗小黑3 天前
Pytest项目_day11(fixture、conftest)
pytest
测试开发技术7 天前
软件测试中,pytest 运行完成后,如何自动发送邮件?
开发语言·python·pytest·接口测试·面试题
丿罗小黑7 天前
Pytest项目_day08(setup、teardown前置后置操作)
pytest
测试19987 天前
Pytest中实现自动生成测试用例脚本代码
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试
丿罗小黑8 天前
Pytest项目_day04(Python做接口请求)
pytest