Skip to main content

Fully asynchronous unit test

Project description

asyncUnittest

asyncUnittest is created for fully asynchronous unit test,which is inspired by unittest. I hear that the newest unittest has support asynchronous test already. Well, maybe that is a better choice.


Install · Usage ·


Install

asyncUnittest in PyPI

pip install asyncUnittest

Usage

simple example

from asyncUnittest import AsyncTestCase


class Test(AsyncTestCase):
    enable_test = True

    @classmethod
    async def setUpClass(cls) -> None:
        print('setUpClass')

    async def setUp(self) -> None:
        print('setUp')

    async def test1(self):
        print('test1')

    async def test2(self):
        print('test2')

    def test3(self):
        print('test3')

    async def tearDown(self) -> None:
        print('tearDown')

    @classmethod
    async def tearDownClass(cls) -> None:
        print('tearDownClass')

AsyncTestCase

If you are familiar with unittest, this is intuitive. Implement your test case class by inheriting 'AsyncTestCase' imported from asyncUnittest.

enable_test

The property 'enable_test' is True as default. You do not need to explicitly define it. If you want to close the inheriting test case, assign False to it.

setUpClass

The test case runs with the first step of calling and awaiting 'setUpClass', before anything else happens.

setUp

All test methods run concurrently. Before each test method runs, its belonging 'setUp' would be called and awaited.

test method

A test method may be a normal function or coroutine function.

Any method is a test method as long as string 'test' is in their name's lower case copy, starting or ending with no ' _'. For example, test_connect and cancel_test are OK, but _test_connect, _test_connect_, _cancel_test_ and cancel_test_ will be ignored. You can close some test method by adding '_'.

tearDown

After each test method completes, its belonging 'tearDown' would be called and awaited.

tearDownClass

After everything else completes in the test case, the last step is to call and await 'tearDownClass'.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncUnittest-1.4.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

asyncUnittest-1.4.0-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page