Merge lp:~jml/testtools/export-reactor-720749 into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 215
Proposed branch: lp:~jml/testtools/export-reactor-720749
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 61 lines (+22/-0)
3 files modified
NEWS (+6/-0)
testtools/deferredruntest.py (+1/-0)
testtools/tests/test_deferredruntest.py (+15/-0)
To merge this branch: bzr merge lp:~jml/testtools/export-reactor-720749
Reviewer Review Type Date Requested Status
testtools developers Pending
Review via email: mp+68572@code.launchpad.net

Commit message

Export reactor to tests running under AsynchronousDeferredRunTest.

Description of the change

Fixes bug 720749 by setting the reactor attribute on a test case.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-07-20 08:48:46 +0000
3+++ NEWS 2011-07-20 16:47:27 +0000
4@@ -4,6 +4,12 @@
5 NEXT
6 ~~~~
7
8+Changes
9+-------
10+
11+* Tests that run with ``AsynchronousDeferredRunTest`` now have the ``reactor``
12+ attribute set to the running reactor. (Jonathan Lange, #720749)
13+
14 Improvements
15 ------------
16
17
18=== modified file 'testtools/deferredruntest.py'
19--- testtools/deferredruntest.py 2011-04-01 13:45:45 +0000
20+++ testtools/deferredruntest.py 2011-07-20 16:47:27 +0000
21@@ -215,6 +215,7 @@
22
23 def _run_core(self):
24 # Add an observer to trap all logged errors.
25+ self.case.reactor = self._reactor
26 error_observer = _log_observer
27 full_log = StringIO()
28 full_observer = log.FileLogObserver(full_log)
29
30=== modified file 'testtools/tests/test_deferredruntest.py'
31--- testtools/tests/test_deferredruntest.py 2011-01-22 17:56:00 +0000
32+++ testtools/tests/test_deferredruntest.py 2011-07-20 16:47:27 +0000
33@@ -8,6 +8,7 @@
34 from testtools import (
35 skipIf,
36 TestCase,
37+ TestResult,
38 )
39 from testtools.content import (
40 text_content,
41@@ -335,6 +336,20 @@
42 error = result._events[1][2]
43 self.assertThat(error, KeysEqual('traceback', 'twisted-log'))
44
45+ def test_exports_reactor(self):
46+ # The reactor is set as an attribute on the test case.
47+ reactor = self.make_reactor()
48+ timeout = self.make_timeout()
49+ class SomeCase(TestCase):
50+ def test_cruft(self):
51+ self.assertIs(reactor, self.reactor)
52+ test = SomeCase('test_cruft')
53+ runner = self.make_runner(test, timeout)
54+ result = TestResult()
55+ runner.run(result)
56+ self.assertEqual([], result.errors)
57+ self.assertEqual([], result.failures)
58+
59 def test_unhandled_error_from_deferred(self):
60 # If there's a Deferred with an unhandled error, the test fails. Each
61 # unhandled error is reported with a separate traceback.

Subscribers

People subscribed via source and target branches