You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test.support.subTests() does not run asynchronous tests #155411
3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
test.support.subTests() wraps the test method in a synchronous function. For an asynchronous test the wrapper calls it and discards the resulting coroutine without awaiting it, so the test does not run at all.
It is not even reported as an error, because IsolatedAsyncioTestCase decides whether to await the test method with inspect.iscoroutinefunction(), which does not follow __wrapped__, and so does not notice that the test is asynchronous.
importunittestfromtestimportsupportclassTests(unittest.IsolatedAsyncioTestCase):
@support.subTests('a', [1, 2])asyncdeftest_it(self, a):
self.fail('this is never reported')
if__name__=='__main__':
unittest.main()
$ ./python -W always repro.py
Lib/test/support/__init__.py:1124: RuntimeWarning: coroutine 'Tests.test_it' was never awaited
func(self, *args, **kwargs, **subtest_kwargs)
.
----------------------------------------------------------------------
Ran 1 test in 0.006s
OK
None of the 195 subTests() call sites in the stdlib is currently affected, as none of them decorates an async def, but fixing this allows using subTests() in asynchronous tests.
3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
Activity
gh-155411: Fix test.support.subTests() for asynchronous tests (GH-155412
[3.14] gh-155411: Fix test.support.subTests() for asynchronous tests (G…
[3.13] gh-155411: Fix test.support.subTests() for asynchronous tests (G…
pythongh-155411: Fix test.support.subTests() for asynchronous tests (p…
[3.15] gh-155411: Fix test.support.subTests() for asynchronous tests (G…