[Python-ideas] remove coupling between unittest and assertions

Nick Coghlan ncoghlan at gmail.com
Fri Nov 15 12:35:21 CET 2013


On 15 November 2013 17:55, Gregory Salvan <apieum at gmail.com> wrote:
> Hi,
> I would seperate unittest from its assertions.
> I suggest to create the module "assertions" in stdlib.
>
> - it will not change unittest api
> - it improves decoupling and SOC so other testing library will be able to
> share a common base code avoiding duplication
> - it would be great to write guard clauses with more expressive error
> message like that for example:
> from assertions import assert_in
>
> def my_function(*args, **kwargs):
>     assert_in(''option", kwargs)
>     ...
>
> This last point merits more reflexion since "assert" is removed when python
> compiles in optimize mode. A such mecanism can be added further in
> assertions lib.

We've (very briefly) discussed the idea of decoupling the APIs in
http://bugs.python.org/issue18054 (the specific proposal mentioned
there was to standardise the "matcher" concept used in testtools).

I'd certainly like to see something along those lines in Python 3.5 -
having good assertions independent of the assert statement and the
unittest object model would be helpful (although it may still be a
submodule of unittest).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list