2016-07-19 34 views
0

我在CPython 2.7中使用了Tornado 4.4。龍捲風hello_world測試返回599

我複製:

import tornado.ioloop 
import tornado.web 

class MainHandler(tornado.web.RequestHandler): 
    def get(self): 
     self.write("Hello, world") 

def make_app(): 
    return tornado.web.Application([ 
     (r"/", MainHandler), 
    ]) 

if __name__ == "__main__": 
    app = make_app() 
    app.listen(8888) 
    tornado.ioloop.IOLoop.current().start() 

http://www.tornadoweb.org/en/stable/guide/structure.html到hello.py,然後:

import hello 

class TestHelloApp(AsyncHTTPTestCase): 
    def get_app(self): 
     return hello.make_app() 

    def test_homepage(self): 
     response = self.fetch('/') 
     self.assertEqual(response.code, 200) 
     self.assertEqual(response.body, 'Hello, world') 

http://www.tornadoweb.org/en/stable/testing.html到test_hello.py

當我運行:

python -m tornado.test.runtests test_hello

我得到:

AssertionError: 599 != 200

要麼我缺少東西或Tornado文檔/代碼需要更新。

回答

0

看起來您錯誤地縮進了hello.py中的代碼。此行不應在所有縮進:

def make_app(): 

也就是說,在龍捲風文檔make_app是一個模塊級的功能,但在你的代碼做了它MainHandler的成員。

+0

我的不好,謝謝傑西指出。但我仍然得到了599。 – pdx9

0

我忘了提及我在VirtualBox/Ubuntu 14.04中執行此測試。事實證明,這是非常重要的,因爲當我直接在OSX或VirtualBox/Debian Jessie中運行它時,我沒有得到599。雖然Ubuntu 14.04來自Jessie,但我仍然期待着類似的行爲,但我仍然感到困惑。