Search code examples
pythonunit-testingstack-tracepython-unittesttraceback

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


I am using unittest for UI testing and HTMLTestRunner to publish test reports. To have more neat reports, I want to remove/disable traceback on output. I found sys.tracebacklimit = 0 effective but it just works on Errors and apparenty error stack is separate from failure stack in unittest.TestResult. How can I have traceback removed from failures as well?


Solution

  • I changed HTMLTestRunner addError and addFailure and replaces _exc_str with " ". Also you can replace it with any desired string.