Generating Clear Visual HTML Test Reports with unittestreport: Quick Start, Features, and Extensions
This article explains how to quickly generate clear, visual HTML test reports using the unittestreport framework, covering installation, basic usage, data‑driven testing, multithreading, email notifications, SSL fixes, and compatibility extensions with HTMLTestRunner for both unittest and pytest environments.
In daily testing, publishing clear and readable test reports speeds up result comprehension, and automated testing benefits greatly from quickly generated visual HTML reports.
01. unittestreport Overview unittestreport is an open‑source extension built on unittest that creates HTML test reports. Install it via pip install unittestreport for unittest or pip install pytest-testreport for pytest.
02. Quick Start The framework provides a TestRunner class that replaces unittest's TextTestRunner . After running tests, it automatically produces an HTML report. Key parameters include suite , filename , report_dir , tester , desc , title , and templates (1‑3) to select report styles.
03. High‑Frequency Features unittestreport adds functionalities not native to unittest, such as data‑driven testing, parallel execution, and result push.
04. Data‑Driven Testing Using the ddt library, unittestreport supports list, JSON, and YAML data sources. Decorate test classes with @ddt and use @list_data , @json_data , or @yaml_data to feed data into test methods.
05. Multithreaded Execution & Retry The enhanced TestRunner.run() accepts thread_count for parallel threads, count for retry attempts, and interval for pause between retries. Threads are grouped by test class to preserve order within a class while allowing inter‑class concurrency.
06. Email Push unittestreport can send the generated report via SMTP using TestRunner.send_email() after test execution.
07. Email SSL Error Fix By default only ports 25 and 465 are supported; the framework was extended to handle port 587 (TLS) by modifying the SMTP connection logic, enabling secure email delivery on the TLS port.
08. Compatibility with HTMLTestRunner To reuse existing HTMLTestRunner reports, the source of HTMLTestRunner was merged into unittestreport, its __init__.py updated, and the main flow adjusted to import and invoke HTMLTestRunner, allowing seamless switching between report styles.
09. Extending TestRunner.run() HTMLTestRunner originally required a suite argument. The method was updated to accept an optional suite, providing a default when omitted, thus aligning its signature with unittestreport's TestRunner.run() and supporting both invocation styles.
Overall, the article demonstrates how unittestreport streamlines the creation of clear, visual HTML test reports and details practical enhancements for data‑driven tests, parallel execution, email notifications, SSL support, and cross‑framework compatibility.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.