如何将 unittest.TestResult 更改为 disable/remove 失败回溯?

How to change unittest.TestResult to disable/remove traceback on Failures?

我正在使用 unittest 进行 UI 测试,并使用 HTMLTestRunner 发布测试报告。 为了获得更简洁的报告,我想 remove/disable 回溯输出。我发现 sys.tracebacklimit = 0 有效,但它只适用于 错误 并且显然错误堆栈与 unittest.TestResult 中的故障堆栈分开。我怎样才能从失败中删除回溯?

我更改了 HTMLTestRunner addErroraddFailure,并将 _exc_str 替换为 " "。您也可以将其替换为任何所需的字符串。