HtmlTestRunner
HtmlTestRunner copied to clipboard
Report not showing test description
- HtmlTestRunner version: 1.2.1
- Python version: 3.8.1
- Operating System: macOS Catalina 10.15.5
Description
Hi team first all thanks for making this amazing package.
Here's my issue:
I tried to produce the HTML report but somehow the shortDescription()
is not shown in the report properly. It shows the name of a test method rather than the docstring
of it. But the example on README does show the short descriptions rather than the names. Screenshot:

Now: showing test method names Expectation: showing test method docstring (description)
What I Did
# Building the TestSuite.
suite = TestSuite([MySuite1, MySuite2.])
# Run tests.
if __name__ == '__main__':
kwargs = {
"report_title" : "Database Comparison Test",
"report_name" : 'db_comparison',
"combine_reports" : True
}
runner = HTMLTestRunner(**kwargs)
result = runner.run(suite)
Example test method
def test_client_id(self):
"""some desc goes here"""
And I guess it's the similar situation as in #65 @lilikppratama would you please provide some codes to help us out?
Thanks
@TonyWu3027 @lilikppratama
I don't understand how this used to work like in the examples. However, in order to get test_case.test_docstring available to the template you could add one of the lines below to the _TestInfo class.
diff --git a/HtmlTestRunner/result.py b/HtmlTestRunner/result.py
index 96fb431..c8873be 100644
--- a/HtmlTestRunner/result.py
+++ b/HtmlTestRunner/result.py
@@ -96,6 +96,13 @@ class _TestInfo(object):
else:
self.test_id = subTest.id()
+ # https://docs.python.org/3/library/unittest.html#unittest.TestCase.shortDescription
+ # This returns the first line of doc string:
+ # self.test_docstring = test_method.shortDescription()
+
+ # This returns the full docstring:
+ # self.test_docstring = test_method._testMethodDoc
+
def id(self):
return self.test_id
Related to: #65
Thanks @mwchambers ! I traced back into the commits before a bit and found why.
-
In 378ec89,
_HtmlTestResult.getDescription()
does return the docstring if existed or the name of function otherwise. (https://github.com/oldani/HtmlTestRunner/commit/378ec89af701d21156011231fef5cd15e37b98e5#diff-547f9bc2ea640b56134da72aa353479bR103) -
But now after a merge the method will only return the name of the function regardless of whether that function has a docstring or not. (https://github.com/oldani/HtmlTestRunner/blame/master/HtmlTestRunner/result.py#L167)
Wondering if I should change it back to what it was or not lol.
Thanks for the tips mate, cheers.
Hi @TonyWu3027
Did you add the line back in a PR? or how did you manage to show the test description?
Thanks in advance!
Hi @hasslercastro
Sorry I didn't really get a chance to make a PR since I used it in a previous project of mine and I'm quite busy with other stuff at the moment. From what I can see, if the method is not called anywhere else than in the _TestInfo
class then it is same to change it back. Hope it helps.
Best, Tony
Hello everyone. Any chance there's been a solution to this? I started using HtmlTestRunner and would like to see the description of each test in my report.
Edit: Here is how I did it,
html_runner = HtmlTestRunner.HTMLTestRunner(
output='reports/',
descriptions=True,
report_title='Random title',
report_name='Random name',
open_in_browser=True,
combine_reports=True,
)
html_runner.run(test_suite)