aiotest: a testing library on top of unittest for asyncio

437 views
Skip to first unread message

Martin Richard

unread,
May 11, 2015, 4:37:03 PM5/11/15
to python...@googlegroups.com
Hi,

I would like to talk about a testing library I wrote on top of unittest called aiotest. The goal is to provide a package compatible with the standard unittest package, but which cuts the boilerplate when testing asyncio code.

The code is on github here: https://github.com/Martiusweb/aiotest

I use this library for a project at work, and it currently integrates the most common features one should need, such as :

 - a TestCase class which creates and recycle the loop after each test, allows setUp, tearDown and test functions to be coroutine functions, and checks that the loop ran during a test,
 - CoroutineMock, which allows to mock a coroutine, and modified versions of Mock, MagicMock which can return a CoroutineMock object instead of a MagicMock object when a spec or spec_set is defined and the original member of the mocked object/class is a coroutine function,
 - mock.patch() are also updated so they return the enhanced Mock and MagickMock objects, or CoroutineMock is the patched value is a coroutine function.

I will add the package to PyPI later this week, since It's my first package, I'd like to be extra careful.

I am obviously open to suggestions, feature requests and bug reports!

Cheers,
Martin

Ludovic Gasc

unread,
May 11, 2015, 5:39:47 PM5/11/15
to Martin Richard, python-tulip
Hi Martin,

Thanks a lot to contribute to improve AsyncIO toolbox.

However, before to add your library on the wiki page: https://github.com/python/asyncio/wiki/ThirdParty
I've spotted we already have an AsyncIO library called aiotest, made by Victor: https://bitbucket.org/haypo/aiotest/ already present on PyPI: https://pypi.python.org/pypi/aiotest

I should suggest to rename your library to avoid comprehension errors from newcomers.

Have a nice night.

--
Ludovic Gasc (GMLudo)

Martin Richard

unread,
May 12, 2015, 3:09:26 AM5/12/15
to python...@googlegroups.com, marti...@gmail.com
Ah, too bad I didn't check that before... and I wanted to be "extra-careful"!

I changed the name to asynctest and uploaded the project on pypi: https://pypi.python.org/pypi/asynctest

Thanks Ludovic!

Andrew Svetlov

unread,
May 12, 2015, 6:10:44 AM5/12/15
to Martin Richard, python...@googlegroups.com
Hmm. I always prefer to disable default event loop in tests by
`asyncio.set_event_loop(None)` call.
--
Thanks,
Andrew Svetlov

Martin Richard

unread,
May 12, 2015, 7:23:10 AM5/12/15
to Andrew Svetlov, python...@googlegroups.com
Passing the loop explicitly when writing a library is a good practice, but not a requirement. Hence, I think that it's better not to break asyncio.get_event_loop() by default.

However, I will probably add a configuration layer to TestCase in order to configure the behaviour of the loop (choose the Proactor event loop, for instance), I can add the option to disable the default loop.
--
Martin Richard
www.martiusweb.net

Ludovic Gasc

unread,
May 12, 2015, 2:07:54 PM5/12/15
to Martin Richard, python-tulip
I've added your library: https://github.com/python/asyncio/wiki/ThirdParty#unit-testing
BTW, you should also post on: http://asyncio.org/

--
Ludovic Gasc (GMLudo)

Reply all
Reply to author
Forward
0 new messages