Immanuel Scholz wrote: >>> i = 1 >>> def foo(): >>> global i >>> i += 1 >>> return i >>> >>> def test_foo(): >>> assert foo() == 3 >>> >>> >>> Is there a common solution to this, other than the annoying >>> >>> foo_result = foo() >>> assert foo_result == 3 >>> >>> thingie? Maybe py.test could preemptive cache all calls to assert >>> beforehand? Is this possible? >>> >> It's sophisticated, as long as it's lazy - ie when assert works (is not >> broken) there is no magic at all. There are few solutions. One is the >> above solution, and we do this all the time in pypy. Other one is to use >> --nomagic, but you don't get all nice info out of that :) >> > > --nomagic isn't a cute solution either, as you get no information at all > about the problem, and when people unaware of this run the test code > without the option, they still get false information. > > I was thinking of a more comfortable solution. Is it possible in python > to capture the assert call before it is made and cache the argument and > then call to the original "assert"? This way, you don't have to remember > to cache the call everytime yourself. > > > The stuff is most annoying when testing functions that are some kind of > generator and spits out another value on each call. > > Ciao, Imi. > > I don't know :) I can help you dig into codebase if you would like to (btw, our primary channel is IRC for such things, as it's way easier, #pylib on irc.freenode.net)
Cheers, fijal :. _______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev