the further adventures of

Mike Pirnat

a leaf on the wind

« Previous Post Next Post »

Failing Tests? FFFFFFFUUUUUUUUUUUU...

On Friday I ran across this modest proposal to make the output of Python's unittest2 more closely resemble the emotional state of the tester when there are a lot of failing unit tests. Once my coworkers were done asking if I was all right, or if they should be worried about the cackling and giggles coming from my cube, I resolved to make this dream a reality.

My workplace has settled on the nose testing framework. Like other frameworks, nose offers a plugin architecture to allow all kinds of additional customization and tweaks, and since I had never written one before, it seemed like this might be a good opportunity to give it a try. I found the plugin development docs to be a little too terse and not terribly n00b-friendly, but over the course of a couple of hours I was able to cobble something together. (I mostly ended up cheating off of Kumar McMillan's nose-nicedots, which got me over the hurdle of realizing I needed my own flavor of TestResult to make sure I got the usual stack trace output while still emitting the F's and U's correctly.)

It basically goes like this:

$ nosetests --with-f7u12

.......FFFFFFFFUUUUUUUUUUUUUUUU..U..U..U..U..U..U.
======================================================================
FAIL: test_f7u12.TestGeneratesLotsOfFailures.test_generates_failures(7,)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/Users/mpirnat/Documents/code/python/nose-f7u12/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py",
line 197, in runTest
    self.test(*self.arg)
File
"/Users/mpirnat/Documents/code/python/nose-f7u12/src/examples/test_f7u12.py",
line 15, in _make_a_test
    assert False
AssertionError


< lots more test failure output; use your imagination... >


Ran 50 tests in 0.021s

FAILED (errors=30)

After some wrangling with PyPI (which could also be a lot friendlier to a packaging n00b--big thanks to Michael Foord for helping set me straight), it should be easy_install-able, or you can grab the source from Github (patches welcome!). And if you prefer pytest over nose, it looks like they've got a plugin too.

It's a tremendously silly thing, but it brought me some joy; I hope it can brighten your day too, or at least bring some comfort and commiseration to your test failure rage.

blog comments powered by Disqus

« Previous Post Next Post »