From: Greg Ward Date: Sun, 21 Jun 2015 14:20:31 +0000 (-0400) Subject: Clarify the role and meaning of self.fetch() in AsyncHTTPTestCase. X-Git-Tag: v4.3.0b1~89^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=177e03415a2f73ffb1691c0eaaa2ced94c0ae8b8;p=thirdparty%2Ftornado.git Clarify the role and meaning of self.fetch() in AsyncHTTPTestCase. The example code should just show the simple, obvious thing to do: call self.fetch(). Text afterwards explains how this relates to stop() and wait(). --- diff --git a/tornado/testing.py b/tornado/testing.py index 93f0dbe14..5bac5de70 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -338,13 +338,17 @@ class AsyncHTTPTestCase(AsyncTestCase): return Application([('/', MyHandler)...]) def test_homepage(self): - # The following two lines are equivalent to - # response = self.fetch('/') - # but are shown in full here to demonstrate explicit use - # of self.stop and self.wait. - self.http_client.fetch(self.get_url('/'), self.stop) - response = self.wait() - # test contents of response + response = self.fetch('/') + + That call to ``self.fetch()`` is equivalent to :: + + self.http_client.fetch(self.get_url('/'), self.stop) + response = self.wait() + + which illustrates how AsyncTestCase can turn an asynchronous operation, + like ``http_client.fetch()``, into a synchronous operation. If you need + to do other asynchronous operations in tests, you'll probably need to use + ``stop()`` and ``wait()`` yourself. """ def setUp(self): super(AsyncHTTPTestCase, self).setUp()