UnitTesting icon indicating copy to clipboard operation
UnitTesting copied to clipboard

Ideas for asyncio

Open rwols opened this issue 5 years ago • 1 comments

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

rwols avatar Dec 29 '19 11:12 rwols

it seems that we could borrow some idea from https://github.com/kwarunek/aiounittest

randy3k avatar Dec 30 '19 03:12 randy3k