Regarding unit testing in web2py, I think there are two basic approaches.
One approach is to slightly modify the way you write and call the unit test
file, and rely on web2py to build its environment in the usual way. This
method is described in the post you referenced (
http://web2py.com/AlterEgo/default/show/260). Note, in that post, the
example test.py code executes the controller being tested via:
execfile("applications/api/controllers/10.py", globals())
However, I'm not sure that is actually necessary, as it is also possible to
specify a controller in the command line call instead:
python web2py.py -S myapp/mycontroller -M -R applications/myapp/tests/test.
py
That will run the test.py file in the environment of the mycontroller
controller of myapp (including all the models).
The alternative method is to write and run unit tests as usual, and
manually build the needed web2py environment within the unit test itself.
The web2py Test Runner library was designed with this approach, and it
includes some methods to make it easy to build the web2py environment
automatically. See http://packages.python.org/web2py_utils/test_runner.html
and http://pypi.python.org/pypi/web2py_utils/0.0.13dev.
You might also want to look at
http://www.web2pyslices.com/slice/show/1465/unittesting-doctesting-and-userinterface-testing
.
Finally, for basic testing of controller functions, doctests can be
included in the controller function docstrings, and the admin interface
includes functionality to automatically run all such doctests.
Anthony
On Sunday, September 2, 2012 10:57:47 PM UTC-4, viniciusban wrote:
>
> Hi guys.
>
> I'd like to know if this still is the recommended way to write unit
> tests in Web2py: http://www.web2py.com/AlterEgo/default/show/260
>
> --
> Vinicius Assef
>
--