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 : %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
>>> cb.ge #auto completion in the shell
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 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!