[tahoe-lafs-trac-stream] [Tahoe-LAFS] #3947: Use `async def` for tests in src/allmydata/test/mutable/test_version.py

Tahoe-LAFS trac at tahoe-lafs.org
Wed Nov 30 14:28:42 UTC 2022


#3947: Use `async def` for tests in src/allmydata/test/mutable/test_version.py
---------------------+---------------------------
 Reporter:  exarkun  |          Owner:
     Type:  defect   |         Status:  new
 Priority:  normal   |      Milestone:  undecided
Component:  unknown  |        Version:  n/a
 Keywords:           |  Launchpad Bug:
---------------------+---------------------------
 Since Twisted 22.8 we can write `async def` test methods (with either
 trial or testtools).

 Let's do some of that.

 The transformation is basically mechanical.

 {{{
 def test_foo(self):
    d = some_deferred()
    d.addCallback(lambda x: some_function(x))
    return d
 }}}

 becomes either

 {{{
 async def test_foo(self):
     x = await some_deferred()
     some_function(x)
 }}}

 or

 {{{
 async def test_foo(self):
     x = await some_deferred()
     await some_function(x)
 }}}

 `Deferred.addCallback(f)` is happy whether `f` returns a `Deferred` or not
 but `await f()` only works if `f` returns an awaitable - thus the choice
 to make above.

--
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3947>
Tahoe-LAFS <https://Tahoe-LAFS.org>
secure decentralized storage


More information about the tahoe-lafs-trac-stream mailing list