diff --git a/NEWS b/NEWS index e10cf276..20defc5b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,17 @@ testtools NEWS Changes and improvements to testtools_, grouped by release. +NEXT +~~~~ + +Improvements +------------ + +* Make ``extract_result()`` and ``DeferredNotFired`` public APIs in + ``testtools.twistedsupport``. These utilities are useful for extracting + results from synchronous Deferreds in tests. + (Jelmer Vernooij, #546) + 2.8.3 ~~~~~ diff --git a/doc/twisted-support.rst b/doc/twisted-support.rst index 62435929..f90cbbd9 100644 --- a/doc/twisted-support.rst +++ b/doc/twisted-support.rst @@ -38,6 +38,20 @@ See also `Testing Deferreds without the reactor`_ and the `Deferred howto`_. :noindex: +Extracting results from Deferreds +---------------------------------- + +When testing code that returns synchronous +:py:class:`~twisted.internet.defer.Deferred`\s for compatibility reasons, you +may want to extract the result directly instead of using matchers. + +.. autofunction:: testtools.twistedsupport.extract_result + :noindex: + +.. autoexception:: testtools.twistedsupport.DeferredNotFired + :noindex: + + Running tests in the reactor ---------------------------- diff --git a/testtools/twistedsupport/__init__.py b/testtools/twistedsupport/__init__.py index 42cae985..96d8f423 100644 --- a/testtools/twistedsupport/__init__.py +++ b/testtools/twistedsupport/__init__.py @@ -7,8 +7,11 @@ "AsynchronousDeferredRunTest", "AsynchronousDeferredRunTestForBrokenTwisted", "CaptureTwistedLogs", + # Deferred utilities + "DeferredNotFired", "SynchronousDeferredRunTest", "assert_fails_with", + "extract_result", "failed", "flush_logged_errors", "has_no_result", @@ -16,6 +19,10 @@ "succeeded", ] +from ._deferred import ( + DeferredNotFired, + extract_result, +) from ._matchers import ( failed, has_no_result,