[英]How to do a teardown of pytest intermediate results on test fail?
There is enough information on how to setup and share pytest fixtures between tests.关于如何在测试之间设置和共享 pytest 夹具有足够的信息。
But what if a test would create some remote resources and then fail?但是,如果测试会创建一些远程资源然后失败怎么办? How to make pytest to cleanup those resources which haven't existed as fixtures at test beginning?如何使 pytest 在测试开始时清理那些作为夹具不存在的资源?
You can keep a variable in class level您可以在 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.