Index: testing_support/tests/thread_watcher_test.py |
diff --git a/testing_support/tests/thread_watcher_test.py b/testing_support/tests/thread_watcher_test.py |
index 4989f2d8311a5625b9b4c84ef36e9bff95057875..c98be29c985bd74a1b8ef5f086c3847b174c30c3 100644 |
--- a/testing_support/tests/thread_watcher_test.py |
+++ b/testing_support/tests/thread_watcher_test.py |
@@ -28,6 +28,13 @@ class _PuppetThread(threading.Thread): |
self._stop_event.set() |
self.join() |
+class _ResultFake(object): |
+ def __init__(self, value): |
+ self.value = value |
+ |
+ def wasSuccessful(self): |
+ return self.value |
+ |
class ThreadWatcherTestCase(thread_watcher.TestCase): |
def setUp(self): |
@@ -71,6 +78,38 @@ class ThreadWatcherTestCase(thread_watcher.TestCase): |
self.assertNotIn(' Thread stopped while acquiring stacktrace.\n', |
error_message) |
+ def test_extra_threads_unittest_pass(self): |
+ # Test succeeded, so thread_watcher must cause failure. |
+ self.watcher._resultForDoCleanups = _ResultFake(True) |
+ self.watcher.setUp() |
+ self._threads.append(_PuppetThread('foo')) |
+ self.watcher.tearDown() |
+ self.assertEqual(len(self._fail_called), 1) |
+ |
+ def test_extra_threads_unittest_fail(self): |
+ # Test failed already, so thread_watcher must ignore result. |
+ self.watcher._resultForDoCleanups = _ResultFake(False) |
+ self.watcher.setUp() |
+ self._threads.append(_PuppetThread('foo')) |
+ self.watcher.tearDown() |
+ self.assertEqual(self._fail_called, []) |
+ |
+ def test_extra_threads_expect_tests_pass(self): |
+ # Test succeeded, so thread_watcher must cause failure. |
+ self.watcher._test_failed_with_exception = False |
+ self.watcher.setUp() |
+ self._threads.append(_PuppetThread('foo')) |
+ self.watcher.tearDown() |
+ self.assertEqual(len(self._fail_called), 1) |
+ |
+ def test_extra_threads_expect_tests_fail(self): |
+ # Test failed already, so thread_watcher must ignore result. |
+ self.watcher._test_failed_with_exception = True |
+ self.watcher.setUp() |
+ self._threads.append(_PuppetThread('foo')) |
+ self.watcher.tearDown() |
+ self.assertEqual(self._fail_called, []) |
+ |
def test_fail_get_stacktrace(self): |
self.watcher.setUp() |
self._threads.append(_PuppetThread('foo')) |
@@ -108,6 +147,5 @@ class ThreadWatcherTestCaseUsageTest(thread_watcher.TestCase): |
self._threads[-1].stop() |
- |
if __name__ == '__main__': |
unittest.main() |