gpt4 book ai didi

python - 我们可以在 pytest 中有多个 addfinalizer

转载 作者:行者123 更新时间:2023-11-28 21:03:39 25 4
gpt4 key购买 nike

我想在pytest中添加多个finalizer函数,那么是否可以添加多个addfinalizer。如果是,那么执行顺序是什么。任何帮助将不胜感激。

谢谢

最佳答案

您可以添加多个终结器。来自pytest docs :

Both yield and addfinalizer methods work similarly by calling their code after the test ends, but addfinalizer has two key differences over yield:

  1. It is possible to register multiple finalizer functions.
  2. Finalizers will always be called regardless if the fixture setup code raises an exception. This is handy to properly close all resources created by a fixture even if one of them fails to be created/acquired:

这个问题与this other stackoverflow question非常相似,其中讨论了顺序问题(并提供了更好的解决方案)。

关于python - 我们可以在 pytest 中有多个 addfinalizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53314233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com