Created
November 20, 2015 00:21
-
-
Save cablehead/28fce590d88117aeb3a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import functools | |
from decorator import decorator | |
import pytest | |
from tornado import ioloop | |
from tornado import gen | |
@pytest.fixture | |
def loop(): | |
loop = ioloop.IOLoop() | |
loop.make_current() | |
return loop | |
@pytest.fixture | |
def three(loop): | |
print loop | |
return 3 | |
def sleep(loop, s): | |
result = gen.Future() | |
loop.add_timeout( | |
time.time()+s, lambda: result.set_result(None)) | |
return result | |
@decorator | |
def async_test(f, loop, *a, **kw): | |
f = gen.coroutine(f) | |
loop.run_sync(functools.partial(f, loop, *a, **kw)) | |
loop.stop() | |
@async_test | |
def test_main(loop, three): | |
print three | |
yield sleep(loop, three) | |
print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment