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

Pra*_*ams 3 python pytest python-3.x python-unittest

我需要在整个测试套件运行后或在整个测试退出时执行命令。我在unittest中看到tearDownhook ,但在ruby中没有after-testsuite hook或类似的东西。at_exit

有什么方法我可以遵循吗unittestpytest或对此进行任何调整

MrB*_*men 5

您可以在 pytest 中使用会话范围的固定装置。顾名思义,它使您可以在整个测试会话之前和之后运行代码:

\n
@pytest.fixture(scope=\'session\', autouse=True)\ndef session_setup_teardown():\n    # setup code goes here if needed\n    yield\n    cleanup_testsuite()\n
Run Code Online (Sandbox Code Playgroud)\n

你最好把这个装置放到顶层conftest.py.

\n

我不知道 as\xc3\xadmilar 的功能unittest- 最接近的可能是tearDownModule每个测试模块执行一次。

\n