I am using twisted to pass in a variable into my django environment so I have to run the twisted server. Hence when I am testing my django app I really need to run the twisted code
it runs something like this:
def wsgi_resource():
pool = threadpool.ThreadPool()
pool.start()
# Allow Ctrl-C to get you out cleanly:
reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
wsgi_resource = wsgi.WSGIResource(reactor, pool, WSGIHandler())
return wsgi_resource
wsgi_root = wsgi_resource()
reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root))
How do I even begin testing for this piece of code? I have to run twisted because my views uses something like this:
blockingCallFromThread( reactor, engine.push_message, user_hexid, room_hexid, message)
to call the variable that I passed into it.
You can write tests with Twisted's built-in test runner, trial , assuming that you start your WSGI threadpool before each test and stop it afterwards (in setUp and tearDown).
The upcoming 11.1 release includes new documentation for doing test-driven development with Twisted using Trial. Until that's available in the official location, here's a temporary link to a buildbot build of our the documentation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.