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
exarkun commented 2022-04-02 13:52:35 +00:00
Owner

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.
tahoe-lafs added the
dev-infrastructure
normal
enhancement
n/a
labels 2022-04-02 13:52:35 +00:00
tahoe-lafs added this to the undecided milestone 2022-04-02 13:52:35 +00:00
itamarst commented 2022-04-06 15:27:36 +00:00
Author
Owner

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).
exarkun commented 2022-11-30 14:24:25 +00:00
Author
Owner

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 project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

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