BeautifulReport Documentation

repository·master·Indexed 19 days ago

https://github.com/testerliferaymond/beautifulreport

A Python package for generating visual HTML reports for unittest-based automation testing suites. It integrates with unittest.TestResult to transform test results into reports and provides a @add_test_img decorator for attaching screenshots to specific test cases.

Tokens
793
Snippets
4
Records
4
Agent score
16%

What's inside BeautifulReport

  1. Generate a unittest report with BeautifulReport

    master

    BeautifulReport is a visualization package for unittest automation testing. It integrates with unittest.TestResult to transform test results into a visual report. To use it, discover your test suite using unittest.defaultTestLoader.discover and pass the suite to the BeautifulReport constructor, then call the .report() method.

    import unittest
    from BeautifulReport import BeautifulReport
    
    if __name__ == '__main__':
        # Discover tests in the '../tests' directory
        test_suite = unittest.defaultTestLoader.discover('../tests', pattern='test*.py')
        
        # Initialize BeautifulReport with the test suite
        result = BeautifulReport(test_suite)
        
        # Generate the report
        result.report(filename='测试报告', description='测试deafult报告', log_path='report')
  2. Add screenshots to reports using @add_test_img

    master

    You can attach screenshots to specific test cases using the @BeautifulReport.add_test_img decorator.

    Usage Requirements:

    • Directory: You must create an img folder in the current working directory of your test project. This is where images are expected to be stored.
    • Lifecycle: The image file passed to the decorator does not need to exist before the test runs; it can be generated during the test execution.
    • Interaction: In the generated HTML report, clicking on a thumbnail will open the full-sized screenshot.

    Example:

    import unittest
    from BeautifulReport import BeautifulReport
    
    class UnittestCaseSecond(unittest.TestCase):
        
        @BeautifulReport.add_test_img('测试报告.png')
        def test_is_none(self):
            # Logic to generate/save the image
            save_some_img('测试报告.png')
            self.assertIsNone(None)
    @BeautifulReport.add_test_img('测试报告.png')
    def test_is_none(self):
        save_some_img('测试报告.png')
        self.assertIsNone(None)
  3. Reference the BeautifulReport.report method

    master

    The report method generates the final HTML report file.

    Parameters:

    • filename: The name of the test report. If not specified, the default filename is report.html.
    • description: A description or title displayed in the test report.
    • log_path: The directory path where log files will be written. Defaults to '.'.
    result.report(filename='测试报告', description='测试deafult报告', log_path='report')