[TIP] A rare philosophical thought

Ben Finney ben+python at benfinney.id.au
Fri Aug 1 19:59:29 PDT 2008

"Noah Gift" <noah.gift at gmail.com> writes:

> One interpretation of this comment could be literal. I hate
> passionately the syntax of the standard library unit test framework.
> For me, it is indeed, a bunch of boilerplate code, with a
> Shakespearean English API. All of this, "Where for art though
> equality..." stuff, is a bit annoying to me.

That's an artefact of the deliberate decision to emulate the existing
xUnit frameworks. It's certainly not the only way to go, but it's a de
facto standard, so I'm glad to have it in the standard library.

>  What is wrong with a plain assert?

Nothing, as far as it goes. The main improvements people usually seem
to want over a plain assert is: standard rich failure messages for
common assertions, saying what was expected; and the addition of
fixtures and other improvements to approach the Don't Repeat Yourself

> What makes unit test worst is that people often make custom unit
> test frameworks that involve non-trivial level of abstraction. I
> guess I feel like this defeats part of the purpose of testing, which
> is to show someone how your code work, not design yet another OO
> masterpiece.

I would call this a very minor part of unit tests, ancillary to the
main purpose: to show the *computer* how your code units *should*
behave, in a way that the computer can check automatically and show
you exactly where the actual behaviour diverges from the expectations.

Another way of saying this is that precision and automatability are
more valuable in a unit test suite than "does it serve as API

> Personally I really like doctest because, while it isn't perfect, it
> is simple, and easy to understand.

I also like doctest, and am glad that we have both unittest and
doctest. They serve rather different purposes.

 \       “I love to go down to the schoolyard and watch all the little |
  `\   children jump up and down and run around yelling and screaming. |
_o__)             They don't know I'm only using blanks.” —Emo Philips |
Ben Finney

More information about the testing-in-python mailing list