2014-05-12 63 views
0

這裏有一個要點: https://gist.github.com/pconerly/e07ba1294266b38c6a5a龍捲風測試失敗「類型錯誤:__init __()恰恰1參數(2給出)」

所有的文件都在同一目錄下。 我在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需要有一個回調方法的初始化參數?在我看過的任何示例中,我都沒有看到過這種模式。

回答

3

我懷疑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() 
+0

就是這樣。 -_-;謝謝一堆! – Civilian

相關問題