完成所有测试后 pytest 会话未结束

Tro*_*ski 5 python pytest jenkins

我正在尝试将 pytests 集成到我的 Jenkins 项目中,但 Jenkins 工作无法完成,因为 pytest 的测试会话尚未结束。

\n\n

这是我能想到的最简单的例子:

\n\n

Python测试:

\n\n
import pytest\nimport sys, time\nsys.path.append(\'../../bindings/python\')\n\nclass TestControl():\n    def test_sanity_check(self):\n        """\n        Basic Test\n        """\n        assert (True)\n
Run Code Online (Sandbox Code Playgroud)\n\n

控制台命令和输出:

\n\n
 python git:(ed25b33) \xe2\x9c\x97 sudo nano test_control.py \n\xe2\x9e\x9c  python git:(ed25b33) \xe2\x9c\x97 sudo python3 -m pytest -s test_control.py::TestControl::test_sanity_check\n=============================================================================================================================== test session starts ===============================================================================================================================\nplatform linux -- Python 3.4.3, pytest-3.3.2, py-1.5.2, pluggy-0.6.0\nrootdir: /var/lib/jenkins/workspace/examples/python, inifile:\ncollected 1 item                                                                                                                                                                                                                                                                  \n\ntest_control.py .                                                                                                                                                                                                                                                           [100%]\n\n============================================================================================================================ 1 passed in 0.67 seconds =============================================================================================================================\n
Run Code Online (Sandbox Code Playgroud)\n\n

测试显示 100% 已完成,但由于某种原因并未终止会话。我尝试在脚本中添加 sys.exit() 但会导致错误。我只需要测试来释放控制台,这样我的 Jenkins 工作就可以完成。

\n

Tro*_*ski 3

事实证明,我有一个 setup_class,但没有 Teadown_class,并且我的类实例仍然处于活动状态,并阻止测试会话结束。