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
I'm planning to rely completely on asyncio for ST4 and LSP, and I want to be able to run tests with asyncio.
I'm envisioning this possibility:
frommy_packageimportget_my_custom_loopfromunittestingimportAsyncTestCaseimportasyncioclassMyTestSuite(AsyncTestCase):
# customization point: allow the user to define its own loop# if this function is not overridden, UnitTesting should provide its own loopdefget_running_loop(self) ->asyncio.AbstractEventLoop:
returnget_my_custom_loop()
# customization point: are the tests in this suite allowed to run all at once or one after the other?defallowed_to_run_parallel(self) ->bool:
returnFalse# customization point if get_running_loop is overridden: we want to know if the loop is running on the UI thread# or notdefloop_is_on_main_thread(self) ->bool:
returnFalse# an actual testasyncdeftest_foo(self) ->None:
awaitasyncio.sleep(1)
self.assertTrue(True)
Asyncio is supported by underlying unittest library via IsolatedAsyncioTestCase class. Note this class starting a dedicated thread running an isolated eventloop in.
That's not very different to how sublime_aio provides a global event loop.
Running an asyncio event loop on ST's main thread would require a custom event loop implementation running code via sublime.set_timeout(), which as a result may additional work to avoid compatibility issues with libraries such as anyio or sniffio.
Activity
randy3k commentedon Dec 30, 2019
it seems that we could borrow some idea from https://github.com/kwarunek/aiounittest
deathaxe commentedon Nov 10, 2025
Asyncio is supported by underlying
unittestlibrary viaIsolatedAsyncioTestCaseclass. Note this class starting a dedicated thread running an isolated eventloop in.see: #278
That's not very different to how sublime_aio provides a global event loop.
Running an asyncio event loop on ST's main thread would require a custom event loop implementation running code via
sublime.set_timeout(), which as a result may additional work to avoid compatibility issues with libraries such as anyio or sniffio.