It is inconvenient to test code using async def using Tahoe's unittest-based testing tools #3886

Open
opened 2022-04-02 13:52:35 +00:00 by exarkun · 2 comments

There are four base classes for test cases in allmydata.test.common - SyncTestCase, AsyncTestCase, AsyncBrokenTestCase, and TrialTestCase.

None of these allow definition of a test using async def with the behavior you would expect (behavior analogous to what you get from AsyncTestCase and a test method returning a Deferred).

As async def becomes the more popular way to define asynchronous functions and pervasive direct use of Deferred becomes less popular, it would probably be nice if it were at least as convenient to test with async def as it is with Deferred-returning functions.

There are four base classes for test cases in `allmydata.test.common` - `SyncTestCase`, `AsyncTestCase`, `AsyncBrokenTestCase`, and `TrialTestCase`. None of these allow definition of a test using `async def` with the behavior you would expect (behavior analogous to what you get from `AsyncTestCase` and a test method returning a Deferred). As `async def` becomes the more popular way to define asynchronous functions and pervasive direct use of `Deferred` becomes less popular, it would probably be nice if it were at least as convenient to test with `async def` as it is with `Deferred`-returning functions.
exarkun added the
dev-infrastructure
normal
enhancement
n/a
labels 2022-04-02 13:52:35 +00:00
exarkun added this to the undecided milestone 2022-04-02 13:52:35 +00:00

There's a decorator that enables one solution to this in test_storage_https.py, async_to_defered (once https://github.com/tahoe-lafs/tahoe-lafs/pull/1189 is merged).

There's a decorator that enables one solution to this in `test_storage_https.py`, `async_to_defered` (once <https://github.com/tahoe-lafs/tahoe-lafs/pull/1189> is merged).
Author

It turns out the change in Twisted 22.8 to make maybeDeferred support coroutines makes both trial and testtools work with async def test methods.

It turns out the change in Twisted 22.8 to make maybeDeferred support coroutines makes both trial and testtools work with `async def` test methods.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: tahoe-lafs/trac-2024-07-25#3886
No description provided.