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

Barry Warsaw barry at python.org
Thu Feb 19 22:04:54 CET 2015


On Feb 19, 2015, at 09:32 PM, Nick Coghlan wrote:

>So from my perspective (being one of the aforementioned C
>programmers), I see this question as not so much about the assert
>statement per se, but rather a more philosophical question:
>
>* is testing code categorically different from production code?
>* if yes, should assert statements be handled differently in testing code?
>* if yes, how should that difference be communicated to readers and to
>the interpreter?
>
>(FWIW, I'm personally inclined to answer the first two questions with
>"yes", but haven't got any ideas as far as the third one goes)

I'm of the same mind.

asserts in the code are almost like documentation.  When I write them I'm
usually thinking "this can't possibly happen, but maybe I forgot something".
That's very different from an assertion in test code which says "let's make
sure the outcome of this contrived call is what I expect it to be".

So to me, using the unittest.assert* methods makes that difference obvious,
though I'll admit that sometimes I'm in the same boat of having to dip into
the documentation to remember if it's assertMultilineEqual() or
assertMultiLineEqual().  I find most of the assert* methods fairly easy to
remember.

Cheers,
-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150219/b2be1162/attachment-0001.sig>


More information about the Python-ideas mailing list