运行测试RuntimeError时收到错误:IOLoop已在运行。该怎么办?

塞尔希

尝试在龙卷风中编写针对Web身份验证的测试。但是收到错误:

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已在运行

不知道该怎么办。需要帮助。代码如下:

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)
本·达内尔

AsyncHTTPTestCase支持两种模式:使用self.stop的传统/旧版模式self.wait,以及使用的较新模式@gen_test为一种模式设计的功能在另一种模式下不起作用;self.fetch是为前一种模式设计的。

您可以通过两种方式编写此测试。首先,使用self.fetch,就像您编写的一样,但是@gen_test删除装饰器。其次,这是带有的版本@gen_test

@tornado.testing.gen_test
def test_http_fetch_login(self):
    data = urllib.parse.urlencode(dict(username='user', password='123456'))
    response = yield self.http_client.fetch("http://localhost:8888/web/auth/login", method="POST", body=data)
    self.assertIn('http test', response.body)

区别在于使用yield self.http_client.fetch而不是self.fetch@gen_test版本通常更“现代”,可让您以编写应用程序的方式编写测试,但是它有一个很大的缺点:您可以调用self.fetch('/'),它会自动填充为测试启动的服务器的主机和端口。 ,但self.http_client.fetch您必须构造完整的url。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如果删除了正在运行的方法的对象,该怎么办?

使用ping时收到DUP。我该怎么办?

运行任何离子命令时出现离子异常,该怎么办?

当我运行我的代码时,会弹出: Event { isTrusted: [Getter] } 我该怎么办?

我想运行“ HttpAsyncTask” ...我该怎么办?

队列关闭时该怎么办?

UPS过载时该怎么办?

桌面冻结时该怎么办?

当列是数组时,该怎么办?

RuntimeError:此事件循环已在运行

收到错误消息,指出我的if语句始终为false,我该怎么办?

我的变量不断收到语法错误。我该怎么办

我收到类型错误:无法读取未定义的属性“推送”。我该怎么办?

当HTTP服务器接收到“ Origin:null”标头时,该怎么办?(CORS)

如果在运行Spark应用程序时我的驱动程序或执行程序在Spark中丢失了,该怎么办?

如果我覆盖正在运行的Task实例怎么办?

角度位置重定向仍在运行当前控制器,怎么办?

收到Alamofire的返回数据后,我该怎么办?

每当我尝试运行此代码时,都会出现类似“错误:在行附近解析错误”的错误消息,但我不知道该怎么办?

如果我的测试用户无法收到我的开放测试邀请,我该怎么办

该线程一旦结束就可以运行,该怎么办?

使用eGit导入eclipse后,无法编译运行。我该怎么办?

ServerSocket引发IOException并保持服务器运行时该怎么办

如果要在启动屏幕上运行Ca“,该怎么办?

如果调试无法正常运行(Eclipse IDE,Android SDK),我该怎么办?

在命令提示符下运行curl命令后该怎么办

关闭所有窗口后,virt-manager进程继续运行,该怎么办?

Unity:FlappyBird控件无法在Android上运行,该怎么办?

如果我要使用的CD无法在ubuntu / linux上运行该怎么办