![](/img/trans.png)
[英]Pytest - how to link a specific setup and teardown functions to a specific test function?
[英]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.