← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/export-reactor-720749 into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/export-reactor-720749 into lp:testtools.

Requested reviews:
  testtools developers (testtools-dev)
Related bugs:
  Bug #720749 in testtools: "No public API to get reactor being used by AsynchronousDeferredRunTests"
  https://bugs.launchpad.net/testtools/+bug/720749

For more details, see:
https://code.launchpad.net/~jml/testtools/export-reactor-720749/+merge/68572

Fixes bug 720749 by setting the reactor attribute on a test case.
-- 
https://code.launchpad.net/~jml/testtools/export-reactor-720749/+merge/68572
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/export-reactor-720749 into lp:testtools.
=== modified file 'NEWS'
--- NEWS	2011-07-20 08:48:46 +0000
+++ NEWS	2011-07-20 16:46:29 +0000
@@ -4,6 +4,12 @@
 NEXT
 ~~~~
 
+Changes
+-------
+
+* Tests that run with ``AsynchronousDeferredRunTest`` now have the ``reactor``
+  attribute set to the running reactor. (Jonathan Lange, #720749)
+
 Improvements
 ------------
 

=== modified file 'testtools/deferredruntest.py'
--- testtools/deferredruntest.py	2011-04-01 13:45:45 +0000
+++ testtools/deferredruntest.py	2011-07-20 16:46:29 +0000
@@ -215,6 +215,7 @@
 
     def _run_core(self):
         # Add an observer to trap all logged errors.
+        self.case.reactor = self._reactor
         error_observer = _log_observer
         full_log = StringIO()
         full_observer = log.FileLogObserver(full_log)

=== modified file 'testtools/tests/test_deferredruntest.py'
--- testtools/tests/test_deferredruntest.py	2011-01-22 17:56:00 +0000
+++ testtools/tests/test_deferredruntest.py	2011-07-20 16:46:29 +0000
@@ -8,6 +8,7 @@
 from testtools import (
     skipIf,
     TestCase,
+    TestResult,
     )
 from testtools.content import (
     text_content,
@@ -335,6 +336,20 @@
         error = result._events[1][2]
         self.assertThat(error, KeysEqual('traceback', 'twisted-log'))
 
+    def test_exports_reactor(self):
+        # The reactor is set as an attribute on the test case.
+        reactor = self.make_reactor()
+        timeout = self.make_timeout()
+        class SomeCase(TestCase):
+            def test_cruft(self):
+                self.assertIs(reactor, self.reactor)
+        test = SomeCase('test_cruft')
+        runner = self.make_runner(test, timeout)
+        result = TestResult()
+        runner.run(result)
+        self.assertEqual([], result.errors)
+        self.assertEqual([], result.failures)
+
     def test_unhandled_error_from_deferred(self):
         # If there's a Deferred with an unhandled error, the test fails.  Each
         # unhandled error is reported with a separate traceback.


Follow ups