Skip to content

HTMLRunner passes tests that raise errors and do not reach subtests #102

Description

@ofarajun
  • HtmlTestRunner version: 1.2.1
  • Python version: 3.8
  • Operating System: Ubuntu 20.04

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

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

Screenshot of HTML in browser:
Screenshot from 2024-03-07 15-42-06

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions