Skip to main content

asyncUnittest

asyncUnittest is created for fully asynchronous unit test,which is inspired by unittest. I hear that the newest unittest has supported 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')
        self.assertTrue(0)

    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. It could be omitted.

setUp

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

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 '_'.

assertTrue

"assertTrue" is an assertion method, which asserts all its arguments true. You can find more assertion methods in your editor hint. More will be implemented in the future.

tearDown

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

tearDownClass

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

run

from asyncUnittest import run

When "run" is called, any test case inherited from 'AsyncTestCase' would run. So you can run test cases in one file:

class Test(AsyncTestCase):
    ...


class Test2(AsyncTestCase):
    ...


run()

Or you can import test cases to the target scope and run them concurrently. For example:

from Gear_test import TestGear
from method_run_when_test import TestInstance_run_when
from run_when_test import TestRunWhen
from asyncUnittest import run

run()

result

The test result would be printed in the python console:

setUpClass
setUp
tearDown
setUp
setUp
setUp
test3
tearDown
test1
test2
tearDown
tearDown
tearDownClass
2021-01-21 15:35:00.339 | WARNING  | asyncUnittest.async_unittest:test_one_method:99 - Test method enable_test is complete.Left:['<class '__main__.Test'>.test1', '<class '__main__.Test'>.test2', '<class '__main__.Test'>.test3']

2021-01-21 15:35:00.341 | WARNING  | asyncUnittest.async_unittest:test_one_method:99 - Test method test3 is complete.Left:['<class '__main__.Test'>.test1', '<class '__main__.Test'>.test2']

2021-01-21 15:35:00.341 | WARNING  | asyncUnittest.async_unittest:test_one_method:99 - Test method test1 is complete.Left:['<class '__main__.Test'>.test2']

2021-01-21 15:35:00.342 | WARNING  | asyncUnittest.async_unittest:test_one_method:99 - Test method test2 is complete.Left:[]

2021-01-21 15:35:00.342 | ERROR    | asyncUnittest.async_unittest:run:126 - Traceback (most recent call last):
  File "/Users/90houlaoheshang/Desktop/asyncUnittest/asyncUnittest/async_unittest.py", line 90, in test_one_method
    await asyncio.create_task(test_function())
  File "/Users/90houlaoheshang/Desktop/asyncUnittest/test.py", line 19, in test2
    self.assertTrue(0)
  File "/Users/90houlaoheshang/Desktop/asyncUnittest/asyncUnittest/async_unittest.py", line 30, in assertTrue
    self.assertEqual(True, *args)
  File "/Users/90houlaoheshang/Desktop/asyncUnittest/asyncUnittest/async_unittest.py", line 26, in assertEqual
    raise AssertionError(
AssertionError: 
(True, 0)

items do not equal each other.

2021-01-21 15:35:00.342 | ERROR    | asyncUnittest.async_unittest:run:127 - Spent seconds: 0.008960776000000004, error count:1

"Test method * is complete.Left:[...]" shows which test method is completed and which are still running.

"Traceback" shows error tracebacks.

"Spent seconds...error count..." shows spent time and error count.

Metadata

Release files for asyncUnittest 1.5.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncUnittest 1.5.6
File Size Uploaded Provenance
asyncUnittest-1.5.6.tar.gz 5.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncUnittest 1.5.6
File Interpreter ABI Platform
asyncUnittest-1.5.6-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / asyncUnittest-1.5.6.tar.gz

Download URL asyncUnittest-1.5.6.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2dfece6a1c5b2ec08d7dfd2fe5c748251e6566b5b34be71c3754cdf0100fe2c7
BLAKE2b-256 checksum
How to use checksums
260318fd1b30a0fa205a7b5c08427e931a0000875dfe99d7d7d5a0bb72c79dc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.7

Release files / asyncUnittest-1.5.6-py3-none-any.whl

Download URL asyncUnittest-1.5.6-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ddd7beb53ef1ed1ca132a32bb0677d91c2cb2653fc11ae7df54b65d6b092291
BLAKE2b-256 checksum
How to use checksums
ed12284277ef03d6da0a88e022b6e282a4d8dd4ac552dbc31c6654ca87ff89d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.7

Security for asyncUnittest 1.5.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page