Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ofarajun opened this issue Mar 7, 2024 · 0 comments
Open

Comments

@ofarajun
Copy link

ofarajun commented Mar 7, 2024

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant