Reputation: 42100
I am coming from Java background and absolutely new at Python.
Suppose I have Python program hello.py
that launches a web server like that:
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)
Now I'd like to write an integration test for this server in Python. The test should:
hello.py
to start the server http://localhost:5000/hello
synchronously"Hello!"
How would you suggest write such a test ?
Upvotes: 1
Views: 735
Reputation: 11717
I would recommend you to look at the test
directory of tornado
. It contains all the tornado
tests, that you can launch with python
or nosetests
.
You can have a look at httpserver_test.py
.
Upvotes: 1