OK. I'll move my inner functions to be outside the function, and do the testing that way. I can move them back inside the function when I'm satisfied with the testing results.
On Jun 29, 1:58 pm, mdipierro <[email protected]> wrote: > The inner_function is only interpreted if the outer function is > called. It cannot be tested this way. It may depend for example on > variables that are defined at runtime in the outer function. > > Massimo > > On Jun 29, 3:01 pm, Dan <[email protected]> wrote: > > > That's a good suggestion, Hans. Unfortunately, when I tried it I get > > false OK results -- all the tests are reported as "passing" yet I know > > that one of them should fail. Here is my modified controller code, > > with 2 doctests for the inner function, 1 of which should fail: > > > def my_controller(): > > """ > > here are some doctests: > > > >>> my_controller() > > 35 > > > """ > > > def inner_function(a,b): > > """ > > here are some doctests: > > > >>> inner_function(1,2) > > 3 > > > >>> inner_function(3,4) > > 99 > > """ > > return a + b > > > return 5 * inner_function(3,4) > > > On Jun 29, 11:58 am, Hans Donner <[email protected]> wrote: > > > > place the doctest for inner function in the docstring for > > > innerfunction. now its called before the functions is defined... > > > > On Mon, Jun 29, 2009 at 7:58 PM, Dan<[email protected]> wrote: > > > > > I'd like to create some tests for functions that exist within a > > > > controller using web2py's (very convenient) doctest integration. Is > > > > this possible? > > > > > For example, here is a controller with a subfunction and one test > > > > defined for the controller and another defined for the function within > > > > the controller: > > > > > --- > > > > def my_controller(): > > > > """ > > > > here are some doctests: > > > > > >>> my_controller() > > > > 35 > > > > > >>> inner_function(1,2) > > > > 3 > > > > > """ > > > > > def inner_function(a,b): > > > > return a + b > > > > > return 5 * inner_function(3,4) > > > > --- > > > > and when running tests, I get one error (edited for brevity): > > > > > Line 7, ... in my_controller.__doc__ > > > > Failed example: > > > > inner_function(1,2) > > > > Exception raised: > > > > Traceback (most recent call last): > > > > File "/usr/lib/python2.5/doctest.py", line 1228, in __run > > > > compileflags, 1) in test.globs > > > > File "... in my_controller.__doc__[1]>", line 1, in <module> > > > > NameError: name 'inner_function' is not defined --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

