I noticed that when there is an error raised inside one of the unittest functions, the test fails with the TextTestRunner but not with HTMLTestRunner.
What I Did
def test_raises(self):
with self.subTest("subtest1"):
self.assertTrue(1)
raise ValueError
with self.subTest("subtest2"):
self.assertTrue(0)
if __name__ == "__main__":
runner = HtmlTestRunner.HTMLTestRunner(open_in_browser=True)
result = runner.run(test_suite)
The first subTest passes but because the ValueError raises, the second subTest (which should fail) is never reached. In terminal I see the test fails, but when the HTML is opened in browser it passes (and only lists the first subtest).
Terminal output:
Running tests...
----------------------------------------------------------------------
test_raises (__main__.TestQModel) ... ERROR (0.000748)s
======================================================================
ERROR [0.000748s]: __main__.TestQModel.test_raises
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/cortica/Documents/evaluation_kit/mixed_segdec/qmodel/tests/test_qmodel.py", line 423, in test_raises
raise ValueError
ValueError
----------------------------------------------------------------------
Ran 1 test in 0:00:00
FAILED
(Errors=1)
Generating HTML reports...
reports/TestResults___main__.TestQModel_2024-03-07_15-32-47.html
ERROR - Elapsed Time: 0.26967906951904297 [tests_utils.py:19]
Process finished with exit code 1
Description
I noticed that when there is an error raised inside one of the unittest functions, the test fails with the TextTestRunner but not with HTMLTestRunner.
What I Did
The first subTest passes but because the ValueError raises, the second subTest (which should fail) is never reached. In terminal I see the test fails, but when the HTML is opened in browser it passes (and only lists the first subtest).
Terminal output:
Screenshot of HTML in browser: