GeezerVison is showing github.com — Replace use of `test.test_asyncio.utils.TestCase` with `unittest.IsolatedAsyncioTestCase` · Issue #93357 · python/cpython
Replace use of test.test_asyncio.utils.TestCase with unittest.IsolatedAsyncioTestCase #93357DescriptionFeature or enhancement
Get rid of ad-hoc implementation of async tests by using all relatively new features of standard IsolatedAsyncIoTestCase. For this we need to:
- replace all occurences of
class ...(test_utils.TestCase): with class ...(unittest.IsolatedAsynIoTestCase):
- remove manually created event loops in favor of the builtin one of
IsolatedAsyncIoTestCase
- make loop-dependend test cases
async
- replace multithreading with
asyncio wherever possible
- remove unused imports
- remove the
TestCase and classes it uses (588 -> 346 lines in test_asyncio/utils.py)
Pitch
test_asyncio.utils.TestCase provides no extra functionality over IsolatedAsyncioTestCase. Instead, it takes 200+ lines of code together with two more classes used nowhere else (TestSelector and TestLoop)
TestCase requires manual scheduling of tasks using loop.run_until_complete while IsolatedAsyncioTestCase allows await
TestCase was introduced on 2014 by c73701d while IsolatedAsynIoTestCase was introduced 5 years later by 4dd3e3f
Progress tracking
- find and fix a bug described in gh-97983: Revert "Lay the foundation for further work in asyncio.test_streams: port server cases to IsolatedAsyncioTestCase" #98015 (comment)
- test/test_asyncgen.py
- test/test_coroutines.py
- test/test_pdb.py
- test/test_asyncio/test_base_events.py
- test/test_asyncio/test_events.py
- test/test_asyncio/test_futures.py
- test/test_asyncio/test_pep492.py
- test/test_asyncio/test_proactor_events.py
- test/test_asyncio/test_sendfile.py
- test/test_asyncio/test_sock_lowlevel.py
- test/test_asyncio/test_ssl.py
- test/test_asyncio/test_sslproto.py
- test/test_asyncio/test_streams.py
- test/test_asyncio/test_subprocess.py
- test/test_asyncio/test_tasks.py
- test/test_asyncio/test_unix_events.py
- test/test_asyncio/test_windows_events.py
- replace multithreading with asyncio wherever possible
- remove the
TestCase
- move
asyncio.set_event_loop_policy(None) (a measure agains "test altered the execution environment" warning) into IsolatedAsyncioTestCase's shutdown method
There are 83 cases that use test_asyncio.utils.TestCase
test/test_asyncio/test_base_events.py:class BaseEventTests(test_utils.TestCase):
test/test_asyncio/test_base_events.py:class BaseEventLoopTests(test_utils.TestCase):
test/test_asyncio/test_base_events.py:class BaseEventLoopWithSelectorTests(test_utils.TestCase):
test/test_asyncio/test_base_events.py:class BaseLoopSockSendfileTests(test_utils.TestCase):
test/test_asyncio/test_base_events.py:class TestSelectorUtils(test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py: test_utils.TestCase):
test/test_asyncio/test_events.py:class HandleTests(test_utils.TestCase):
test/test_asyncio/test_futures.py:class DuckTests(test_utils.TestCase):
test/test_asyncio/test_futures.py:class CFutureTests(BaseFutureTests, test_utils.TestCase):
test/test_asyncio/test_futures.py:class CSubFutureTests(BaseFutureTests, test_utils.TestCase):
test/test_asyncio/test_futures.py:class PyFutureTests(BaseFutureTests, test_utils.TestCase):
test/test_asyncio/test_futures.py: test_utils.TestCase):
test/test_asyncio/test_futures.py: test_utils.TestCase):
test/test_asyncio/test_futures.py: test_utils.TestCase):
test/test_asyncio/test_futures.py: test_utils.TestCase):
test/test_asyncio/test_futures.py: test_utils.TestCase):
test/test_asyncio/test_pep492.py:class BaseTest(test_utils.TestCase):
test/test_asyncio/test_proactor_events.py:class ProactorSocketTransportTests(test_utils.TestCase):
test/test_asyncio/test_proactor_events.py:class ProactorDatagramTransportTests(test_utils.TestCase):
test/test_asyncio/test_proactor_events.py:class BaseProactorEventLoopTests(test_utils.TestCase):
test/test_asyncio/test_proactor_events.py:class ProactorEventLoopUnixSockSendfileTests(test_utils.TestCase):
test/test_asyncio/test_selector_events.py:class BaseSelectorEventLoopTests(test_utils.TestCase):
test/test_asyncio/test_selector_events.py:class SelectorTransportTests(test_utils.TestCase):
test/test_asyncio/test_selector_events.py:class SelectorSocketTransportTests(test_utils.TestCase):
test/test_asyncio/test_selector_events.py:class SelectorSocketTransportBufferedProtocolTests(test_utils.TestCase):
test/test_asyncio/test_selector_events.py:class SelectorDatagramTransportTests(test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sendfile.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_sock_lowlevel.py: test_utils.TestCase):
test/test_asyncio/test_ssl.py:class TestSSL(test_utils.TestCase):
test/test_asyncio/test_sslproto.py:class SslProtoHandshakeTests(test_utils.TestCase):
test/test_asyncio/test_streams.py:class StreamTests(test_utils.TestCase):
test/test_asyncio/test_subprocess.py:class SubprocessTransportTests(test_utils.TestCase):
test/test_asyncio/test_subprocess.py: test_utils.TestCase):
test/test_asyncio/test_subprocess.py: test_utils.TestCase):
test/test_asyncio/test_subprocess.py: test_utils.TestCase):
test/test_asyncio/test_subprocess.py: test_utils.TestCase):
test/test_asyncio/test_subprocess.py: test_utils.TestCase):
test/test_asyncio/test_subprocess.py: class SubprocessProactorTests(SubprocessMixin, test_utils.TestCase):
test/test_asyncio/test_tasks.py: test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CTask_CFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CTaskSubclass_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CTask_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py: test_utils.TestCase):
test/test_asyncio/test_tasks.py:class PyTask_PyFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CTask_Future_Tests(test_utils.TestCase):
test/test_asyncio/test_tasks.py:class PyIntrospectionTests(test_utils.TestCase, BaseTaskIntrospectionTests):
test/test_asyncio/test_tasks.py:class CIntrospectionTests(test_utils.TestCase, BaseTaskIntrospectionTests):
test/test_asyncio/test_tasks.py:class PyCurrentLoopTests(BaseCurrentLoopTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CCurrentLoopTests(BaseCurrentLoopTests, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class GenericTaskTests(test_utils.TestCase):
test/test_asyncio/test_tasks.py:class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
test/test_asyncio/test_tasks.py:class RunCoroutineThreadsafeTests(test_utils.TestCase):
test/test_asyncio/test_tasks.py:class SleepTests(test_utils.TestCase):
test/test_asyncio/test_tasks.py:class CompatibilityTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class SelectorEventLoopSignalTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class UnixReadPipeTransportTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class UnixWritePipeTransportTests(test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class SafeChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
test/test_asyncio/test_unix_events.py:class FastChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
test/test_asyncio/test_windows_events.py:class ProactorLoopCtrlC(test_utils.TestCase):
test/test_asyncio/test_windows_events.py:class ProactorMultithreading(test_utils.TestCase):
test/test_asyncio/test_windows_events.py:class ProactorTests(test_utils.TestCase):
test/test_asyncio/test_windows_events.py:class WinPolicyTests(test_utils.TestCase):
Linked PRs
Activitychanged the title [-]Replace use of `test.test_asyncio.utils.TestCase` with `unittest.IsolatedAsynIoTestCase`[/-] [+]Replace use of `test.test_asyncio.utils.TestCase` with `unittest.IsolatedAsyncioTestCase`[/+] on May 30, 2022added 2 commits that reference this issue on Oct 4, 2022gh-93357: Start porting asyncio server test cases to IsolatedAsyncioT… added a commit that references this issue on Oct 7, 2022gh-97983: Revert "Lay the foundation for further work in asyncio.test… kumaraditya303 commented on Oct 27, 2022 If we want to continue with this, then IMO this needs to be done early in the dev cycle so we have time to fixup the CI if it breaks. We certainly don't want to deal with unstable CI at the beta stage. arhadthedev commented on Oct 27, 2022 @kumaraditya303 You're right; I'll return to this issue this weekend and start with stabilization of reverted gh-98015. arhadthedev commented on Oct 30, 2022 Put on hold until gh-98219 is resolved (it probably will fix Altered environment on Windows and Env changed in buildbot in gh-97983). kumaraditya303 commented on Apr 19, 2023 I'm going to just close this now, it is not the best use of our time to port these tests as it doesn't increase test coverage and chance of breaking CI is very high especially as asyncio is very flaky. When I'll remove child watcher I may port some tests to ease writing new tests but not other things.
MetadataMetadataStatusShow more project fields StatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|