繁体   English   中英

如何在测试失败时拆解 pytest 中间结果?

[英]How to do a teardown of pytest intermediate results on test fail?

关于如何在测试之间设置和共享 pytest 夹具有足够的信息。

但是,如果测试会创建一些远程资源然后失败怎么办? 如何使 pytest 在测试开始时清理那些作为夹具不存在的资源?

您可以在 class 级别保留变量

@pytest.mark.usefixtures("run_for_test")
class TestExample:

    __some_resource = None

    @pytest.fixture
    def run_for_test(self):
        set_up()
        yield
        if self.__some_resource:
            self.__some_resource.cleanup()

    def test_example(self):
        self.__some_resource = SomeResource()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM