Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Last active December 18, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgoldberg/5744573 to your computer and use it in GitHub Desktop.
Save cgoldberg/5744573 to your computer and use it in GitHub Desktop.
Example using concurrencytest module: https://github.com/cgoldberg/concurrencytest
#!/usr/bin/env python
#
# Example using `concurrencytest`:
# https://github.com/cgoldberg/concurrencytest
import time
import unittest
from concurrencytest import ConcurrentTestSuite, fork_for_tests
class SampleTestCase(unittest.TestCase):
def test_it(self):
time.sleep(0.5)
if __name__ == '__main__':
# load a TestSuite with 50x TestCases for demo
loader = unittest.TestLoader()
suite = unittest.TestSuite()
for _ in range(50):
suite.addTests(loader.loadTestsFromTestCase(SampleTestCase))
print('Loaded %d test cases...' % suite.countTestCases())
runner = unittest.TextTestRunner()
print('\nRun tests sequentially:')
runner.run(suite)
print('\nRun same tests across 50 processes:')
concurrent_suite = ConcurrentTestSuite(suite, fork_for_tests(50))
runner.run(concurrent_suite)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment