question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How would you use ward with asyncio/trio/curio?

See original GitHub issue
from ward import test, xfail


@xfail('but seriously.')
@test('async functions should fail')
async def _():
    assert False

Naturally this should not pass, but indeed it does. image

So I tried writing a decorator just to see if I could force the async to be sync.

import functools as ft
import asyncio

from ward import test, xfail


def async_test(fn):
    @ft.wraps(fn)
    def _async_wrapper(*args, **kwargs):
        loop = asyncio.get_event_loop()
        return loop.run_until_complete(fn(*args, **kwargs))

    return _async_wrapper


@xfail('but seriously.')
@test('async functions should fail')
@async_test
async def _():
    assert False

and it passed! … but I know for certain it’s not actually working. I can put literally anything in the anon function under @async_test and ward will tell me it passes.

So my assumption is that ward currently will not support async testing… but maybe I’m not smart enough to figure it out. :~)

- SN

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
darrenburnscommented, Feb 23, 2020

Just as an update to this, after thinking about it I’ve got an update planned that’ll allow you to define your tests with async def and just use the standard @test decorator:

Screenshot 2020-02-23 at 16 00 05

It still needs work, but hopefully this will land soon!

0reactions
boonhapuscommented, Mar 22, 2020

Interesting. I’m admittedly new to the world of async testing, so I’m not aware of what is/isn’t standard practice. It makes sense to me why there is a need for a synchronous runner, even if tests are async in isolation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WTF is Ward?! - New PoE 3.15 Defense System - YouTube
Ward is a new defensive layer introduced in Path of Exile 3.15 Expedition, which prevents a flat amount of damage taken on any...
Read more >
Runtime for writing reliable asynchronous applications with Rust
We need some time to stabilize our APIs and collect user feedback. ... within the Python ecosystem you've got asyncio, Trio, Curio, etc....
Read more >
Vision Control: Step By Step Warding Guide for LoL - Mobalytics
This can be used to your advantage by deploying an alternative ward and wasting the enemies time clearing the ward and refusing them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found