竜巻でWeb認証のテストを書くようにしてください。 しかし、受信エラー:テスト中にエラーが発生するRuntimeError:IOLoopが既に実行されています。何をすべきか?
C:\python3\lib\site-packages\tornado\testing.py:402: in fetch
return self.wait()
C:\python3\lib\site-packages\tornado\testing.py:323: in wait
self.io_loop.start()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tornado.platform.select.SelectIOLoop object at 0x00B73B50>
def start(self):
if self._running:
raise RuntimeError("IOLoop is already running")
E RuntimeError: IOLoop is already running
が何をするか分かりません。 help.hereコードである必要があります。self.stop
とself.wait
を使用して伝統的な/レガシーモード、および@gen_test
を使用して、新しいモード:
import pytest
import tornado
from tornado.testing import AsyncTestCase
from tornado.testing import AsyncHTTPTestCase
from tornado.httpclient import AsyncHTTPClient
from tornado.httpserver import HTTPServer
from tests.commons.testUtils import TestUtils
from tornado.web import Application, RequestHandler
import urllib.parse
from handlers.authentication.restAuthHandlers import RESTAuthHandler
import app
class TestRESTAuthHandler(AsyncHTTPTestCase):
def get_app(self):
return app
@tornado.testing.gen_test
def test_http_fetch_login(self):
data = urllib.parse.urlencode(dict(username='user', password='123456'))
response = self.fetch("http://localhost:8888/web/auth/login", method="POST", body=data)
self.assertIn('http test', response.body)
削除@ tornado.testing.gen_testそれは働いた。見つかった情報:https://github.com/tornadoweb/tornado/issues/1154 – Serhiy