How can I make my assertions smarter?

Stuart Hungerford stuart.hungerford at webone.com.au
Mon Nov 1 05:50:47 EST 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 foo.py line 42: spoon.shape == 'bent'

which would appear at line 42 of foo.py 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,

Stu





More information about the Python-list mailing list