asynctest
The package asynctest is built on top of the standard unittest module and cuts down boilerplate code when testing libraries for asyncio.
Currently, asynctest targets the “selector” model, hence, some features will not (yet?) work with Windows’ proactor.
Documentation
Full documentation is available at http://asynctest.readthedocs.org/en/latest/. It includes a tutorial with tested examples of how to use TestCase or mocks.
Features
TestCases
Initialize and close a loop created for each test (it can be configurated), if the loop uses a selector, it will be updated with a TestSelector object wrapping the original selector (see below),
if the test function is a coroutine function or returns a coroutine, it will run on the loop,
TestCase.setUp() and TestCase.tearDown() can be coroutine functions,
control post-test checks with @fail_on, for instance, the test fail if the loop didn’t run, some optional checks can be activated,
ClockedTestCase allows to control the loop clock and run timed events without waiting the wall clock.
Mock and CoroutineMock
CoroutineMock is a new Mock class which mocks a coroutine function, and returns a coroutine when called,
MagicMock supports asynchronous context managers and asynchronous iterators,
NonCallableMock, Mock and CoroutineMock can return CoroutineMock objects when its attributes are get if there is a matching attribute in the spec (or spec_set) object which is a coroutine function,
patch(), patch.object(), patch.multiple() return a MagickMock or CoroutineMock object by default, according to the patched target,
patch(), patch.object(), patch.multiple() handle generators and coroutines and their behavior can be controled when the generator or coroutine pauses,
all the patch() methods can decorate coroutine functions,
mock_open() returns a MagickMock object by default.
return_once() can be used with Mock.side_effect to return a value only once when a mock is called.
Selectors
The module asynctest.selector provides classes to mock objects performing IO (files, sockets, etc).
FileMock is a special type of mock which represents a file. FileMock.fileno() returns a special value which allows to identify uniquely the mock,
SocketMock is a special type of FileMock which uses socket.socket as spec,
TestSelector is a custom selector able to wrap a real selector implementation and deal with FileMock objects, it can replace a selector loop by calling loop._selector = TestSelector(loop._selector), and will intercept mock so they don’t get registered to the actual selector.
set_read_ready() and set_write_ready() to force read and write event callbacks to be scheduled on the loop, as if the selector scheduled them.
Helpers
the coroutine exhaust_callbacks(loop) returns once all the callbacks which should be called immediately are executed, which is useful when the test author needs to assert things which are not yet executed by the loop.
Roadmap
I hope I will find time to develop and release the following features:
set of warnings against common mistakes
proactor support
Tests
asynctest is unit tested. You can run asynctest test suite with this command:
$ PYTHONPATH=. python -m unittest test
Metadata
Release files for asynctest 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| asynctest-0.13.0.tar.gz | 42.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asynctest-0.13.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.7 kB
Release files / asynctest-0.13.0.tar.gz
| Download URL | asynctest-0.13.0.tar.gz |
|---|---|
| Size | 42.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac
|
|
BLAKE2b-256 checksum How to use checksums |
0c0f6056f4435923d2f8c89ac9ef2d18506a569348d8f9cc827b0dd7a4c8acc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1
|
Release files / asynctest-0.13.0-py3-none-any.whl
| Download URL | asynctest-0.13.0-py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676
|
|
BLAKE2b-256 checksum How to use checksums |
e8b68d17e169d577ca7678b11cd0d3ceebb0a6089a7f4a2de4b945fe4b1c86db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1
|
Security for asynctest 0.13.0
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.