嘗試編寫龍捲風網絡認證測試。 但收到錯誤:運行測試時收到錯誤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是代碼:
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