Skip to content

@pytest.inlineCallbacks but for async def's #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
altendky opened this issue Sep 11, 2018 · 3 comments
Open

@pytest.inlineCallbacks but for async def's #31

altendky opened this issue Sep 11, 2018 · 3 comments

Comments

@altendky
Copy link
Member

How about a decorator to allow directly writing async def tests instead of having to wrap them with @pytest.inlineCallbacks decorated tests.

https://github.com/altendky/altendpyqt5/pull/10/files#diff-7531f542e8da5192e38a81a441db749e

async def async_await_for_signal():
    timer = altendpyqt5.tests.utils.singleshot_immediate_timer()
    await altendpyqt5.twisted.signal_as_deferred(timer.timeout)

@pytest.inlineCallbacks
def test_await_for_signal():
    yield twisted.internet.defer.ensureDeferred(async_await_for_signal())

Unless maybe I just haven't thought of an easy way to handle this with existing pieces.

@altendky
Copy link
Member Author

I'm not sure what to call it or how @decorator.decorator works but... maybe this is a start?

@decorator.decorator
def asyncCallbacks(f, *args, **kwargs):
    @pytest.inlineCallbacks
    def wrapper(*args, **kwargs):
        yield twisted.internet.defer.ensureDeferred(f())

    return wrapper

altendky added a commit to altendky/alqtendpy that referenced this issue Sep 12, 2018
@altendky
Copy link
Member Author

Drop the @decorator.decorator stuff. That was a false positive working... Without it it actually runs the tests and passes/fails appropriately.

@altendky
Copy link
Member Author

Then of course the option most like the existing inlineCallbacks actually ends up working with fixtures as well.

@decorator.decorator
def asyncCallbacks(fun, *args, **kw):
    return twisted.internet.defer.ensureDeferred(fun(*args, **kw))

(someday I'll make a PR with tests...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant