How can I make my assertions smarter?

Stuart Hungerford stuart.hungerford at
Mon Nov 1 11:50:47 CET 1999

Hi all,

I'm using some simple functions to implement crude precondition,
postcondition and invariant checking in Python classes.

(Tim: please be gentle ;-)

Is there some neat way to wrap these tests up so I can print any
code expression that fails, e.g:

     Precondition failed line 42: spoon.shape == 'bent'

which would appear at line 42 of as

     pre(spoon.shape == 'bent')

I can see how to use environment variables or global variables to
selectively enable precondtions etc, although any hints for doing that
would be appreciated too.

Thanks in advance,


More information about the Python-list mailing list