【发布时间】:2015-10-07 04:02:38
【问题描述】:
我正在使用 Rethinkdb 和 Tornado 以及 rethinkdb.set_loop_type("tornado")
我正在使用 python unittests 来测试我的服务器路由。
这是我的单元测试基类:
class ServerTest(AsyncHTTPTestCase):
def setUp(self):
super(ServerTest, self).setUp()
def get_app(self):
return Application(self.routes, debug = False)
def post(self, route, data):
result = self.fetch("/%s" % route, method = "POST",
body = json.dumps(data)).body
return json.loads(result)
def tearDown(self):
super(ServerTest, self).tearDown()
conn = yield r.connect()
yield r.db("test").table("test_table").delete().run(conn)
conn.close()
我注意到setUp 运行正常,但tearDown 没有。我所有的单元测试都正常通过,但不调用 tearDown 中的打印语句。
编辑:我已将其范围缩小到我在 tearDown 中调用 yield 的事实。
编辑:将@gen.coroutine 添加到 tearDown 显示打印语句,但不对数据库执行删除
【问题讨论】:
标签: python-2.7 tornado python-unittest rethinkdb-python