gpt4 book ai didi

python - 为 pytest bdd 设置和拆除函数

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

我正在尝试使用 pytest-bdd 进行设置和拆卸模块。我知道使用 behave 你可以用 before_all 和 after_all 模块做一个 environment.py 文件。我如何在 pytest-bdd 中执行此操作

我研究了“经典的 xunit 样式设置”插件,但在我尝试时它不起作用。 (我知道这与 py-test 而不是 py-test bdd 更相关)。

最佳答案

你可以只声明一个 pytest.fixtureautouse=true 以及你想要的任何范围。然后,您可以使用 request fixture 来指定拆解。例如:

@pytest.fixture(autouse=True, scope='module')
def setup(request):

# Setup code

def fin():
# Teardown code

request.addfinalizer(fin)

关于python - 为 pytest bdd 设置和拆除函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389132/

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