Hopefully a simple question, but it doesn’t seem to be covered in the documentation or web2py book…
I’ve got a web2py controller method that looks something like:
def mymethod():
'''
doctests go here
'''
param1 = request.vars['param1']
param2 = request.vars['param2']
param3 = request.vars['param3']
# Stuff happens...
return dict(result=result)
with the parameters being passed in as request variables as per the documentation
Is there any way to build a doctest (inline with the method definition) to evaluate the return value of a call such as mymethod(param1=9, param2='a', param3=3.7)?
Thanks in advance
Just put the desired values in request.vars within the doctest:
To get the doctest right, you can play around in a web2py shell, which you can start as follows:
That will give you a Python shell in an environment with your application’s model files executed (that’s what the -M option does). Because mycontroller is specified, you’ll also be able to call any function in mycontroller. Run some commands in the shell and then paste the session into your docstring.