mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-30 06:53:09 +00:00
ebcaafcded
While running tests for a python tool, the tests' outputs get printed in whatever order they happen to run, without any indication as to which output belongs to which test. Unittest supports capturing these outputs and printing them as part of the test summaries, but when a failure or error occurs it switches back to printing as the tests run. Testtools and subunit tests can do the same as their parts inherit from unittest, but they don't outright expose this functionality. On the unittest side, enable output buffering for the custom test result class. Try to avoid ugly outputs by not printing stdout/stderr before the test summary for low verbosity levels and for successful tests. On the subunit side, implement a custom TestProtocolClient that enables the same underlying functionality and injects the captured streams as additional test details. This causes them to be merged into their test's error traceback message, which is later rebuilt into an exception and passed to our unittest report class. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> |
||
---|---|---|
.. | ||
.gitignore | ||
__init__.py | ||
concurrencytest.py | ||
README.md |
concurrencytest
Python testtools extension for running unittest suites concurrently.
Install from PyPI:
pip install concurrencytest
Requires:
- testtools :
pip install testtools
- python-subunit :
pip install python-subunit
Example:
import time
import unittest
from concurrencytest import ConcurrentTestSuite, fork_for_tests
class SampleTestCase(unittest.TestCase):
"""Dummy tests that sleep for demo."""
def test_me_1(self):
time.sleep(0.5)
def test_me_2(self):
time.sleep(0.5)
def test_me_3(self):
time.sleep(0.5)
def test_me_4(self):
time.sleep(0.5)
# Load tests from SampleTestCase defined above
suite = unittest.TestLoader().loadTestsFromTestCase(SampleTestCase)
runner = unittest.TextTestRunner()
# Run tests sequentially
runner.run(suite)
# Run same tests across 4 processes
suite = unittest.TestLoader().loadTestsFromTestCase(SampleTestCase)
concurrent_suite = ConcurrentTestSuite(suite, fork_for_tests(4))
runner.run(concurrent_suite)
Output:
....
----------------------------------------------------------------------
Ran 4 tests in 2.003s
OK
....
----------------------------------------------------------------------
Ran 4 tests in 0.504s
OK