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

Report not showing test description #71

Open
TonyWu3027 opened this issue Jul 16, 2020 · 6 comments
Open

Report not showing test description #71

TonyWu3027 opened this issue Jul 16, 2020 · 6 comments

Comments

@TonyWu3027
Copy link

  • 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
Copy link
Author

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

Thanks

@mwchambers
Copy link

mwchambers commented Jul 29, 2020

@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

@TonyWu3027
Copy link
Author

Thanks @mwchambers ! I traced back into the commits before a bit and found why.

Wondering if I should change it back to what it was or not lol.

Thanks for the tips mate, cheers.

@hasslercastro
Copy link

Hi @TonyWu3027

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

Thanks in advance!

@TonyWu3027
Copy link
Author

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

@Yorisoft
Copy link

Yorisoft commented Aug 26, 2021

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) 

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

4 participants