[Twisted-Python] Help with trial test failure
Itamar Turner-Trauring
itamar at itamarst.org
Sun Aug 4 13:55:25 MDT 2013
On 08/04/2013 10:25 AM, Benjamin BERTRAND wrote:
> Hi,
>
> I'm trying to write a simple gateway to receive messages using a specific protocol and publish/store them using txredis.
> I wrote a small example that seems to work.
> But the small test I wrote fails:
>
> $ trial gateway/test
> gateway.test.test_example
> GatewayServiceTestCase
> test_messageReceived ... [ERROR]
>
> ===============================================================================
> [ERROR]
> Traceback (most recent call last):
> Failure: twisted.internet.error.ConnectionDone: Connection was closed cleanly.
>
> gateway.test.test_example.GatewayServiceTestCase.test_messageReceived
> -------------------------------------------------------------------------------
> Ran 1 tests in 0.007s
>
>
> As I understand, the connection to the redis server is lost during the test.
> I actually managed to get the test to pass by adding some inlineCallbacks decorator to my messageReceived and lineReceived methods.
> But I don't really understand why that would be needed.
> Could someone explain what is happening?
>
I suspect the inlineCallbacks is irrelevant (and not the way to solve this).
At a guess, what is happening is that something is logging the
connection being lost (perhaps the redis library?). Logging errors in a
unit test makes trial consider that test to have failed: logging an
error suggests something has gone wrong. You can tell trial to expect a
specific error to be logged in your test:
https://twistedmatrix.com/documents/current/core/howto/trial.html#auto11
More information about the Twisted-Python
mailing list