[TIP] Announcing Expecter Gadget
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 .
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 . What do you guys think?
More information about the testing-in-python