summaryrefslogtreecommitdiff
path: root/lib/testtools/testtools/tests/test_testsuite.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/testtools/testtools/tests/test_testsuite.py')
-rw-r--r--lib/testtools/testtools/tests/test_testsuite.py41
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/testtools/testtools/tests/test_testsuite.py b/lib/testtools/testtools/tests/test_testsuite.py
index 05647577cd..426bec4cc4 100644
--- a/lib/testtools/testtools/tests/test_testsuite.py
+++ b/lib/testtools/testtools/tests/test_testsuite.py
@@ -17,32 +17,55 @@ from testtools.tests.helpers import LoggingResult
FunctionFixture = try_import('fixtures.FunctionFixture')
+class Sample(TestCase):
+ def __hash__(self):
+ return id(self)
+ def test_method1(self):
+ pass
+ def test_method2(self):
+ pass
class TestConcurrentTestSuiteRun(TestCase):
def test_trivial(self):
log = []
result = LoggingResult(log)
- class Sample(TestCase):
- def __hash__(self):
- return id(self)
-
- def test_method1(self):
- pass
- def test_method2(self):
- pass
test1 = Sample('test_method1')
test2 = Sample('test_method2')
original_suite = unittest.TestSuite([test1, test2])
suite = ConcurrentTestSuite(original_suite, self.split_suite)
suite.run(result)
- # 0 is the timestamp for the first test starting.
+ # log[0] is the timestamp for the first test starting.
test1 = log[1][1]
test2 = log[-1][1]
self.assertIsInstance(test1, Sample)
self.assertIsInstance(test2, Sample)
self.assertNotEqual(test1.id(), test2.id())
+ def test_wrap_result(self):
+ # ConcurrentTestSuite has a hook for wrapping the per-thread result.
+ wrap_log = []
+
+ def wrap_result(thread_safe_result, thread_number):
+ wrap_log.append(
+ (thread_safe_result.result.decorated, thread_number))
+ return thread_safe_result
+
+ result_log = []
+ result = LoggingResult(result_log)
+ test1 = Sample('test_method1')
+ test2 = Sample('test_method2')
+ original_suite = unittest.TestSuite([test1, test2])
+ suite = ConcurrentTestSuite(
+ original_suite, self.split_suite, wrap_result=wrap_result)
+ suite.run(result)
+ self.assertEqual(
+ [(result, 0),
+ (result, 1),
+ ], wrap_log)
+ # Smoke test to make sure everything ran OK.
+ self.assertNotEqual([], result_log)
+
def split_suite(self, suite):
tests = list(iterate_tests(suite))
return tests[0], tests[1]