[TIP] Announcing Expecter Gadget

Gary Bernhardt gary.bernhardt at gmail.com
Sat Mar 6 19:15:26 PST 2010

I've recently released Expecter Gadget, an expectation (assertion)
library. It provides a nicer syntax than bare asserts or
assertEquals-style functions (IMO). It provides this syntax:

    expect(my_number) == 5

It supports all of the comparison operators and has
context-manager-based exception expectations, like those in recent
versions of nose. You can find examples in the README on PyPI [1].
There isn't yet support for expectations like "this should contain
that", or "this should be contained by that" (which are not the same
type of assertion, by the way!), but adding expectations is very easy.

The recent discussion about AST transformations for pretty assertion
failure messages reminded me to post this. That technique seems pretty
complicated. Expecter Gadget is currently only 62 executable lines of
code, took only an hour to write, gives pretty error messages for
free, and also eliminates the ambiguity between expected and actual
values. (You're stating an expectation about some value you got, so
the expect() always goes around that.)

The code is on BitBucket [2]. What do you guys think?

[1] http://pypi.python.org/pypi/expecter
[2] bitbucket.org/garybernhardt/expecter-gadget


More information about the testing-in-python mailing list