Python Tornado服务器的集成测试

Python Tornado服务器的集成测试,python,integration-testing,tornado,Python,Integration Testing,Tornado,我来自Java背景,对Python一无所知 假设我有一个Python程序hello.py,它可以启动这样一个web服务器: import tornado.web import tornado.httpserver import tornado.ioloop def start_server(port, handler): app = tornado.web.Application([(r"/", handler), ]) server = tornado.httpserver.

我来自Java背景,对Python一无所知

假设我有一个Python程序
hello.py
,它可以启动这样一个web服务器:

import tornado.web
import tornado.httpserver
import tornado.ioloop

def start_server(port, handler):
    app = tornado.web.Application([(r"/", handler), ])
    server = tornado.httpserver.HTTPServer(app)
    server.bind(port)
    server.start(0)  # autodetect number of cores and fork a process for each
    tornado.ioloop.IOLoop.instance().start()

class MyHandler(tornado.web.RequestHandler):

    def get(self):
        self.write("Hello!")

start_server(5000, MyHandler)
现在我想用Python为这个服务器编写一个集成测试。测试应:

  • 运行
    hello.py
    启动服务器
  • 将HTTP GET请求发送到URL
    http://localhost:5000/hello
    同步
  • 检查响应是否==
    “Hello!”
  • 停止服务器

您建议如何编写这样的测试?

我建议您查看目录。它包含所有的
tornado
测试,您可以使用
python
nosetests
启动这些测试


你可以看看。

嗯。。。那里有很多东西,但我没有找到我需要的测试:(可能我遗漏了一些东西。我需要一些非常简单的东西。我想写一个Python脚本,它在一个单独的线程中运行我的服务器,并通过HTTP与服务器通信。在Python中可行吗?似乎你想要类似于此示例的东西,不是吗?