我需要在整个测试套件运行后或在整个测试退出时执行命令。我在 unittest 中看到了 tearDown
Hook ,但在 ruby 中没有 after-testsuite Hook 或类似 at_exit
的等价物。
在 unittest
或 pytest
中有没有我可以遵循的方法?或对此进行任何调整
最佳答案
您可以在 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/