Fundamentals 5 min read

Generating Comprehensive Automated Test Reports with unittest, Multithreading, and BeautifulReport in Python

This article guides readers through setting up a Python environment, installing BeautifulReport, organizing test projects, and combining unittest with multithreading to produce a single, polished HTML test report while addressing common pitfalls and configuration issues.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Generating Comprehensive Automated Test Reports with unittest, Multithreading, and BeautifulReport in Python

The author, an entry‑level test engineer, shares a step‑by‑step walkthrough of creating automated test reports using Python's unittest framework together with multithreading and the BeautifulReport library.

Required environment includes Python 3.6 (or newer) and the tomorrow package, which can be installed via pip install tomorrow . BeautifulReport is obtained either by cloning its GitHub repository with git clone https://github.com/TesterlifeRaymond/BeautifulReport or by downloading the ZIP archive, then placing the entire package into Python's /Lib/site‑packages directory.

The project structure is simple: a case folder holds test case files, a report folder stores the generated HTML reports, and a run_all.py script executes all tests in one run.

Key code snippets illustrate how to invoke the test suite, use unittest.defaultTestLoader.discover for automatic test discovery, and assemble tests with unittest.TestSuite() . The article also notes that unittest + HTMLTestRunner creates multiple report files, whereas BeautifulReport can produce a single consolidated report.

Two main issues are discussed: (1) when running tests in multiple threads, the summary section of the report only reflected the last test class; the author fixed this by editing the BeautifulReport/template/template file so that summary data matches detailed results. (2) Repeated web‑triggered test runs caused test case counts to accumulate because BeautifulReport.py stores results in a global FIELDS['testResult'] dictionary; resetting this dictionary to an empty list before each run resolves the problem.

A concise unittest methodology is provided, covering setup() , teardown() , setUpClass() (with @classmethod ), tearDownClass() , test discovery patterns, and suite construction.

The article concludes with a hope that readers find the guide useful for generating clean, unified test reports and invites feedback for improvement.

Pythontest automationMultithreadingunittestBeautifulReportreport-generation
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.