UnitTesting
UnitTesting copied to clipboard
Ideas for asyncio
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:
from my_package import get_my_custom_loop
from unittesting import AsyncTestCase
import asyncio
class MyTestSuite(AsyncTestCase):
# customization point: allow the user to define its own loop
# if this function is not overridden, UnitTesting should provide its own loop
def get_running_loop(self) -> asyncio.AbstractEventLoop:
return get_my_custom_loop()
# customization point: are the tests in this suite allowed to run all at once or one after the other?
def allowed_to_run_parallel(self) -> bool:
return False
# customization point if get_running_loop is overridden: we want to know if the loop is running on the UI thread
# or not
def loop_is_on_main_thread(self) -> bool:
return False
# an actual test
async def test_foo(self) -> None:
await asyncio.sleep(1)
self.assertTrue(True)
See also: https://github.com/sublimehq/sublime_text/issues/3129
it seems that we could borrow some idea from https://github.com/kwarunek/aiounittest