Skip to content

Instantly share code, notes, and snippets.

@ajdavis
Last active December 15, 2015 08:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ajdavis/5228086 to your computer and use it in GitHub Desktop.
Save ajdavis/5228086 to your computer and use it in GitHub Desktop.
Example of testing a gen.engine coroutine using tornado.testing
from tornado import gen
import tornado.testing
import motor
class MyTestCase(tornado.testing.AsyncTestCase):
def test_thing(self):
client = motor.MotorClient('localhost', 27017, io_loop=self.io_loop)
client.open_sync()
@gen.engine
def f(callback):
collection = client.test.test_collection
yield motor.Op(collection.remove)
yield motor.Op(collection.insert, {'_id': 1, 'x': 17})
doc = yield motor.Op(collection.find_one, {'_id': 1})
self.assertEqual(17, doc['x'])
callback()
f(callback=self.stop)
self.wait()
if __name__ == '__main__':
import unittest
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment