Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / tools / concurrencytest / README.md
1 concurrencytest
2 ===============
3
4 ![testing goats](https://raw.github.com/cgoldberg/concurrencytest/master/testing-goats.png "testing goats")
5
6 Python testtools extension for running unittest suites concurrently.
7
8 ----
9
10 Install from PyPI:
11 ```
12 pip install concurrencytest
13 ```
14
15 ----
16
17 Requires:
18
19  * [testtools](https://pypi.python.org/pypi/testtools) : `pip install testtools`
20  * [python-subunit](https://pypi.python.org/pypi/python-subunit) : `pip install python-subunit`
21
22 ----
23
24 Example:
25
26 ```python
27 import time
28 import unittest
29
30 from concurrencytest import ConcurrentTestSuite, fork_for_tests
31
32
33 class SampleTestCase(unittest.TestCase):
34     """Dummy tests that sleep for demo."""
35
36     def test_me_1(self):
37         time.sleep(0.5)
38
39     def test_me_2(self):
40         time.sleep(0.5)
41
42     def test_me_3(self):
43         time.sleep(0.5)
44
45     def test_me_4(self):
46         time.sleep(0.5)
47
48
49 # Load tests from SampleTestCase defined above
50 suite = unittest.TestLoader().loadTestsFromTestCase(SampleTestCase)
51 runner = unittest.TextTestRunner()
52
53 # Run tests sequentially
54 runner.run(suite)
55
56 # Run same tests across 4 processes
57 suite = unittest.TestLoader().loadTestsFromTestCase(SampleTestCase)
58 concurrent_suite = ConcurrentTestSuite(suite, fork_for_tests(4))
59 runner.run(concurrent_suite)
60 ```
61 Output:
62
63 ```
64 ....
65 ----------------------------------------------------------------------
66 Ran 4 tests in 2.003s
67
68 OK
69 ....
70 ----------------------------------------------------------------------
71 Ran 4 tests in 0.504s
72
73 OK
74 ```