python中setup和teardown怎么用

小编给大家分享一下python中setup和teardown怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

创新互联建站-专业网站定制、快速模板网站建设、高性价比增城网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式增城网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖增城地区。费用合理售后完善,十余年实体公司更值得信赖。

说明

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中setup和teardown怎么用
URL地址:http://pwwzsj.com/article/pgjcpi.html