[Python-ideas] hookable assertions - to support testing utilities and debugging

Nick Coghlan ncoghlan at gmail.com
Thu Feb 19 12:12:23 CET 2015


On 19 February 2015 at 21:05, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, Feb 19, 2015 at 08:25:34AM +0100, Ronny Pfannschmidt wrote:
>>
>> Hi,
>>
>> the idea is to have the assert statement call a global method,
>> just like import does
>>
>> one could then do something like
> [...]
>
> I believe that overloading assert in this fashion is an abuse of assert.
> If we want custom "raise if not this condition" calls, I think we should
> copy unittest and define functions that do what we want, not abuse the
> assert statement.
>
> If you want to (mis)use assert for unit and regression testing, you
> should see the nose third party module and see if that does the sort of
> thing you want.

py.test is the one to look at for this:
http://pytest.org/latest/assert.html#assert-with-the-assert-statement

It (optionally) rewrites the AST for assert statements to make them
suitable for testing purposes rather than being optional runtime
integrity checks.

Cheers,
Nick.

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


More information about the Python-ideas mailing list