Enhance the standard unittest package with features for testing asyncio libraries
Project description
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/,
Features
TestCase and FunctionTestCase
Initialize and close a loop created for each test, 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,
a test fails if the loop did not run during the test.
Mock and CoroutineMock
CoroutineMock is a new Mock class which mocks a coroutine function, and returns a coroutine when called,
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,
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 immediatly 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 (0.7 ?)
proactor support (0.8 ?)
Tests
asynctest is unit tested. You can run asynctest test suite with this command:
$ PYTHONPATH=. python -m unittest test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file asynctest-0.6.0.tar.gz
.
File metadata
- Download URL: asynctest-0.6.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b1e83babfec2657e5c693561b4d2a1f4c712313bba023861b7e8214f0a0d7bf |
|
MD5 | 303ee1332465fccc66a75e82a43e40a5 |
|
BLAKE2b-256 | 09a1e80c65957d1dc8d59efc8be6c6f1b81f7c7ae9b53d9193aa3917de64859e |
File details
Details for the file asynctest-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: asynctest-0.6.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71371e662255673f84e923391d83e563bd35db3a19be3c2b58c0e8cb11d64cc5 |
|
MD5 | fc9d174ea33d31bf82a09de8420239c9 |
|
BLAKE2b-256 | 2a327944fb47b2a538a66aebf677b952ede4bfcf5f485a46a2b17828ced2e502 |