March 8, 2008

Interactive web2py testing

Filed under: behavior driven development, dev, python, test driven development, web2py — michaelangela @ 11:00 am

web2py is a great web development app. It’s under heavy development and the creator answers tons of questions making many updates to the core code in very short order.

In the quest for TDD, now BDD, I wanted to be able to get an interactive session going in iPython. There are some things I had to do to the iPython ipythonrc file, like adding the web2py to the sys.path variable, but it seems to be working.

There are some gotchas. When you import something with iPython, it runs it, or so it seems. I’m still a newbie at this though so I am most likely wrong!

But, this works for my particular setup. In an iPython session:

In [62]: %doctest_mode
*** Pasting of code with “>>>” or “…” has been enabled.
Exception reporting mode: Plain
Doctest mode is: ON

>>> from gluon.globals import Request
>>> from applications.cookbook.models import db
>>> r=Request()
>>> cb=db.Cookbook(r)
>>> cb.ge #auto completion in the shell
cb.getcategory cb.getrecipe
>>> cb.getcategory(1)[‘name’]

So I now have interactive access to the database which is what I want for testing. And I can get doctests straight away as well. That’s pretty cool. This gives shell experimentation similar to Django’s shell app admin. As you can see there is some auto completion going on there as well. Neat!

Oh yes. In my ipythonrc.ini I have the standard

import_mod sys os

and added

execute sys.path.append(‘C:\\path\\to\\web2py’)

and in that session I also did a


Perhaps I can/will make different profiles for different tests but this is the main thing I’ll be testing. I’ll just put those things into the ipythonrc file. I thought I wouldn’t need the sys.path.append AND the os.chdir but both are needed. sys.path.append allows the import, and os.chdir allows autocompletion in the shell.

ScribeFire seems to be causing trouble with the code prompts though. 😦 Trying an edit in Zoundry’s Raven now… and it worked! 🙂


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: