1、pytest 中的 setup 和 teardown

  • 固定函数名称如下(函数名称不能写错
def setup(self):
    print("setup_function--->")

def teardown(self):
    print("teardown_function--->")
  • 实例如下
import pytest

class Test():
    def setup(self):
        print("setup_function--->")

    def teardown(self):
        print("teardown_function--->")

    def test_01(self):
        print("深圳多测师")

    def test_02(self):
        print("广州多测师")

    def test_03(self):
        print("上海多测师")

if __name__ == '__main__':
    pytest.main(["-s","test_demo1.py"])

# 结果如下
test_demo1.py 

setup_function--->
深圳多测师
.teardown_function--->

setup_function--->
广州多测师
.teardown_function--->

setup_function--->
上海多测师
.teardown_function--->

 

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/ZhengYing0813/p/12883925.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!