• 技术文章 >Python技术 >Python基础教程

    python setup和teardown的使用

    小妮浅浅小妮浅浅2021-09-24 09:45:08原创4652

    说明

    1、setup/teardown:每种方法将执行一次,无论是类内还是类外。

    2、Setup:方法运行前执行,表示前置条件。

    必须在每个用例执行前执行一次。

    3、Teardown:方法运行后才能执行,表示资源释放。

    每次用例执行后都会执行一次。

    实例

    # file_name: test_setup.py
    import pytest
    def setup():
        print("...类外setup...")
    def test_create():
        print("类外test_create")
    def test_view():
        print("类外test_view")
    class TestSetupClass:
        def setup(self):
            print("...类内setup...")
        def test_create(self):
            print("类内test_create")
        def test_view(self):
            print("类内test_view")
        def teardown(self):
            print("...类内teardown...")
    def teardown():
        print("...类外teardown...")
    if __name__ == '__main__':
        pytest.main(['-vs', 'test_setup.py'])

    以上就是python setup和teardown的使用,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python setup teardown
    品易云
    上一篇:python如何实现图像等比缩放 下一篇:python绘制散点图的两种方法

    相关文章推荐

    • python循环遍历如何理解• python for语句的应用场景• python如何模拟用户自动打卡• python逻辑取反的实现• python Pytest有什么特点• python如何打印矩阵• Python Modules是什么意思• python三种导入模块的方式• python查找计算函数的整理• python填充压缩的函数总结• python分割拼接函数的介绍• python判断字符串函数的归纳• python如何实现图像等比缩放

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网