On Mon, Jul 1, 2024, at 11:32 AM, Mike Bayer wrote:
hey gang -
I'm adding asyncio support to oslo.db. Fairly major block hit, which I can work around, is that testtools / stestr do not seem to have any provision for asyncio present.
An initial attempt working with it gracefully looked like this (using oslotests base, which is the testtoolsTestBase):
import unittest from oslotest import base
class MyTestSuite(unittest.IsolatedAsyncioTestCase, base.BaseTestCase): # ...
but that didn't work because the degree to which testtools modifies the run() method of unittest.TestCase prevents IsolatedAsyncioTestCase from running awaitable test cases.
Next attempt is this, remove testtools / oslotest from the class hierarchy (which is bad, because we lose all of our testtools patterns):
class MyTestSuite(unittest.IsolatedAsyncioTestCase): # ...
this runs, however stestr sends into the test suite a Result object that is not a subclass of unittest.result.TestResult, it's a "subunit.test_results.AutoTimingTestResultDecorator" that does not TestResult in its MRO; unittest shows a warning that there is no addDuration() method on the result object.
final workaround, patch one on, here's my base:
class BaseAsyncioCase(unittest.IsolatedAsyncioTestCase): def run(self, result=None): # work around stestr sending a result object that's not a # unittest.TestResult result.addDuration = lambda test, elapsed: None return super().run(result=result)
now I can run asyncio tests. But only by ditching testtools entirely.
What would be the correct approach to introducing asyncio support in our test suites given our dependency on testtools?
I think the dependency on testtools was far more important back when we were trying to support python2.6, python2.7 and python3.something. In particular support for addCleanup() is/was important to ensure reliable cleanups of external resources. I think there were also problems with setUp failures maybe not failing test cases in old python unittest (don't quote me on that I don't remember all the details). At this point I suspect the need to only support relatively modern python particularly when we talk about adding asyncio support to stuff means we may get away with stdlib unittest over testtools. Testtools was primarily there to bridge some behavior gaps and ensure consistent behavior between python2 and python3. That is no longer a concern.