【问题标题】:Tornado testing fails with "TypeError: __init__() takes exactly 1 argument (2 given)"龙卷风测试失败,并显示“TypeError:__init__() 恰好需要 1 个参数(给定 2 个)”
【发布时间】:2014-05-12 17:52:07
【问题描述】:

这里有一个要点: https://gist.github.com/pconerly/e07ba1294266b38c6a5a

所有文件都在同一个目录中。 我在 python 2.7.2 上,我的 pip freeze > reqs.txt 很重要。

我在尝试使用AsyncHTTPTestCase 时遇到了问题,它是self.fetch() 函数。我不清楚哪个 __init__ 被错误地调用了。

这是堆栈跟踪:

(smokesignal)peterconerly$ python runtest.py 

Debug app 0.1.0
-------------- Running Test Suite --------------

<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[<test.TestDebug testMethod=test_foo>]>]>]>
E
======================================================================
ERROR: test_foo (test.TestDebug)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/peterconerly/code/tornado_debug/test.py", line 13, in test_foo
    response = self.fetch('/foo')
  File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 333, in fetch
    return self.wait()
  File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 272, in wait
    self.__rethrow()
  File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 208, in __rethrow
    raise_exc_info(failure)
  File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped
    ret = fn(*args, **kwargs)
  File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/httpserver.py", line 328, in _on_headers
    self.request_callback(self._request)
TypeError: __init__() takes exactly 1 argument (2 given)

----------------------------------------------------------------------
Ran 1 test in 0.011s

FAILED (errors=1)
[E 140512 10:36:30 testing:614] FAIL
(smokesignal)peterconerly$ 

我想知道我的DebugApp 是否需要一个回调方法的 init 参数?在我看过的任何示例中,我都没有看到这种模式。

【问题讨论】:

    标签: python testing tornado


    【解决方案1】:

    我怀疑get_app 方法应该返回一个类实例。如果您查看the example provided in the documentation,它会返回tornado.web.Application 的实例:

    def get_app(self):
        return Application([('/', MyHandler)...])
    

    但是你返回一个类型:

    def get_app(self):
        return DebugApp
    

    你可能想要的是:

    def get_app(self):
        return DebugApp()
    

    【讨论】:

    • 就是这样。 -_-;非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多