HtmlTestRunner icon indicating copy to clipboard operation
HtmlTestRunner copied to clipboard

Report not showing test description

Open TonyWu3027 opened this issue 4 years ago • 6 comments

  • 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:

截屏2020-07-16 下午3 10 27

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"""

TonyWu3027 avatar Jul 16 '20 07:07 TonyWu3027

And I guess it's the similar situation as in #65 @lilikppratama would you please provide some codes to help us out?

Thanks

TonyWu3027 avatar Jul 16 '20 07:07 TonyWu3027

@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

mwchambers avatar Jul 29 '20 16:07 mwchambers

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.

TonyWu3027 avatar Jul 30 '20 02:07 TonyWu3027

Hi @TonyWu3027

Did you add the line back in a PR? or how did you manage to show the test description?

Thanks in advance!

hasslercastro avatar Aug 09 '20 20:08 hasslercastro

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

TonyWu3027 avatar Aug 11 '20 05:08 TonyWu3027

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) 

Yorisoft avatar Aug 26 '21 15:08 Yorisoft