Le 4 août 2013 à 21:55, Itamar Turner-Trauring <ita...@itamarst.org> a écrit :
> 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 > I tried to add self.flushLoggedErrors() at the end of the test_messageReceived, but it doesn't help. What is strange is that if I remove the self.redis_factory.client.transport.loseConnection() in the tearDown method, the test is OK, but of course I get an error because the reactor was unclean: gateway.test.test_example GatewayServiceTestCase test_messageReceived ... [OK] [ERROR] =============================================================================== [ERROR] Traceback (most recent call last): Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean. Selectables: <<class 'twisted.internet.tcp.Client'> to ('localhost', 6381) at 10d06de90> gateway.test.test_example.GatewayServiceTestCase.test_messageReceived ------------------------------------------------------------------------------- Ran 1 tests in 0.008s Could the logging come from the tearDown method?? _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python