gpt4 book ai didi

python - 在整个测试套件或 unittest/pytest 中的 at_exit 之后运行命令的 Hook

转载 作者:行者123 更新时间:2023-12-04 09:35:07 26 4
gpt4 key购买 nike

我需要在整个测试套件运行后或在整个测试退出时执行命令。我在 unittest 中看到了 tearDown Hook ,但在 ruby​​ 中没有 after-testsuite Hook 或类似 at_exit 的等价物。

unittestpytest 中有没有我可以遵循的方法?或对此进行任何调整

最佳答案

您可以在 pytest 中使用 session 范围的 fixture 。顾名思义,它使您可以在整个测试 session 之前和之后运行代码:

@pytest.fixture(scope='session', autouse=True)
def session_setup_teardown():
# setup code goes here if needed
yield
cleanup_testsuite()

您最好将此 fixture 放入顶层 conftest.py

我不知道 unittest 中有类似的功能 - 最接近的可能是 tearDownModule每个测试模块执行一次。

关于python - 在整个测试套件或 unittest/pytest 中的 at_exit 之后运行命令的 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62628825/

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