Tornado 3.1.1 with Motor 0.1.1 testing

Just upgrade one project to Tornado 3.1.1 for better exception handling. Also, the project upgrade to Motor 0.1.1 using pip:

pip install -e git+https://github.com/mongodb/motor.git@0.1.1#egg=motor

But when I run my tests based on motor's MotorTest:

class TestFoo(MotorTest):
    ...

    @async_test_engine()
    def test_bar(self, done):
        ...
        yield motor.Op(foo.a_motor_op)

The exception raised:

...
    self.final_callback(getattr(e, 'value', None))
TypeError: <lambda>() takes no arguments (1 given)

Digging into the source code:

# motor/test/__init__.py
class AsyncTestRunner(gen.Runner):
    def __init__(self, gen, timeout):
        # Tornado 2.3 added a second argument to Runner()
       super(AsyncTestRunner, self).__init__(gen, lambda: None)

# tornaod/gen.py
class Runner(object):
    ...
    def run(self):
        ...
        except (StopIteration, Return) as e:
            ...
            self.final_callback(getattr(e, 'value', None))
            self.final_callback = None

So I just hacking one line to fix it:

super(AsyncTestRunner, self).__init__(gen, lambda x: None)

After that, I found a commit on Motor's history:

Tornado 3 compatibility in async_test_engine

Hmm, this commit should merge into Motor release 0.1.1.

喜欢这篇文章就分享到微博吧!
留言请发送到
微信公众帐号
“技术派”

修订历史:


知识共享许可协议

关注@好看簿的蚂蚁

探讨技术、设计、人文和商业
相关的创业话题