[IPython-dev] ANN: SnakeOil - Python testing that doesn't squeak :)
fperez.net at gmail.com
Wed Aug 8 19:39:32 EDT 2007
For a long time I've been really fed up with feeling that the workflow
for testing in Python just isn't very fluid. Generating doctests
requires typing code in text mode, rerunning and modifying them is
annoying, having a standalone test script become a unit test isn't
convenient, and the worst of all, writing parametrized tests in
unittest is a huge PITA.
IPython SVN now has a doctest profile to help a little (and I'll add a
magic to switch at runtime in and out of it, hopefully later tonight).
But that's just a fix for one small annoyance among many.
I know there are testing frameworks out there that address some of
these issues (nose, py.test), but I wanted something small(ish), that
could be used without installing anything (easy to copy inside the
test area of any project and carry it from there, or install it in a
private area after a rename, etc), and that would only depend on the
stdlib (+ ipython, of course, since I use that everywhere).
So the IPython team is happy to announce SnakeOil:
svn co http://ipython.scipy.org/svn/ipython/ipython/branches/saw/sandbox/snakeoil/snakeoil
It's raw alpha, svn-only, lightly tested (about 2k LOC). But it lets
me do *easily* all the things I needed to feel that adding tests
wasn't getting in *my* way. If it doesn't work for you, no worries,
you can get your money back.
It's also fairly hackish in places (surprise, coming from me).
Unittest doesn't lend itself to much of anything, really, so I had to
beat it into behaving in a few places. Still, I wanted to stick to
valid unittest classes so that using SnakeOil would not make your
tests citizens of yet-another-framework.
The doc/ directory has a reST document with some more details as well
as a fully worked set of examples.
- Easy creation of parametric tests (unittests that take arguments).
That includes tests that share state (yes, I know about shared state
in tests. I'm an adult, I know what I'm doing and I need that. Now
unittest, get out of my way and let me actually work).
- Immediate use of any standalone testing script as a unit test, without having
to subclass anything.
- Easy mechanisms for creating valid doctest (.txt) files from true Python
sources, so that one can edit real Python code in an editor and convert that
code to a set of doctests with minimal effort.
This will be integrated in ipython1 later, but for now it sits in the
sandbox. We'll announce when we move it out. We first need to check
that everything works with Twisted trial correctly (I think it does,
but I haven't checked enough yet).
More information about the IPython-dev