New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tornado 4.0.1, AsyncHTTPTestCase, IOLoop is already running #1154
Comments
For more complex tests, you'll need to choose between using self.fetch, self.stop, and self.wait for your asynchronous operations, or using yield like you would in a coroutine. For the latter, you'll probably want some helper functions to construct the correct url like self.fetch does. |
@bdarnell maybe add more information into docs? This can cause difficulty in migrating to the new version. |
To be clear, gen_test and fetch have always been incompatible. It happened to work in 3.2 only if you didn't actually make use of gen_test (by yielding anything). |
@gen_test and self.fetch() are not compatible with one another, although this is not documented (it needs to be, and I need to see if there's some way to make this interaction better) Does this statement still holds true (Tornado 4.2)? I'm trying reproducing the same example documented here and I'm receiving the same 'IOLoop is already running' error. Here is my minimal Gist, am I doing something wrong? What is the correct way of doing this? |
Instead of this:
Do this:
The "self.fetch" method on AsyncHTTPTestCase assumes the IOLoop is not If you're using gen_test, then the IOLoop is always running during your On Thu, Nov 6, 2014 at 1:23 PM, Helder Martins notifications@github.com
|
I tried this, but the problem is that Tornado enforces the
What worked for me in the end was doing the def test_one(self):
self.http_client.fetch(self.get_url('/'), self.stop)
res = self.wait() I created this working gist for those interested. |
In your original gist you did decorate your test_one method with class HelloHandlerTest(AsyncHTTPTestCase):
Was there any problem with that approach? On Fri, Nov 7, 2014 at 12:29 PM, Helder Martins notifications@github.com
|
Note that self.http_client.fetch() and self.fetch() are different: the former is a standard http client call like you'd use in application code, and must be used in conjunction with either gen_test and yield or stop and wait. self.fetch is shorthand for the use of self.http_client.fetch with stop and wait. |
Was there any problem with that approach? |
Right. As Ben said, don't call AsyncHTTPTest's fetch: that is, do not call https://gist.github.com/ajdavis/69b12c7ee77d6ae010d0 On Tue, Nov 11, 2014 at 12:12 PM, Helder Martins notifications@github.com
|
Is this still an issue? Tornado 4.5.1, and docs say class MyTest(AsyncHTTPTestCase):
@gen_test
def test_something(self):
response = yield gen.Task(self.fetch('/')) but I get the same error unless I do this (left everything intact for completeness): from tornado.web import Application, RequestHandler
from tornado.testing import AsyncHTTPTestCase, gen_test
class Http(RequestHandler):
def get(self):
self.write('OK')
class TestHttp(AsyncHTTPTestCase):
def get_app(self):
return Application([(r'/', Http)])
@gen_test
def test_which_works(self):
response = yield self.http_client.fetch(self.get_url('/')) http://www.tornadoweb.org/en/stable/testing.html#tornado.testing.gen_test |
Nothing has changed: |
Yes, but the documentation directly contradicts this, at the location I linked. |
Ah, thanks for the report! I don't think those docs were ever accurate, even when they were written. |
Pointed out in tornadoweb#1154
Pointed out in tornadoweb#1154
After the upgrade, there was a problem with the use of tornado.testing tools.
I'm run this simple code: https://gist.github.com/hgenru/47ad817a199de2e33333
The text was updated successfully, but these errors were encountered: