[TIP] Docstrings in Test methods

Gary Bernhardt gary.bernhardt at gmail.com
Sat Nov 5 11:25:33 PDT 2011

On Sat, Nov 5, 2011 at 8:50 AM, Alfredo Deza <alfredodeza at gmail.com> wrote:
> What do you guys prefer and why (or why not?)

The problem isn't that you need more space for the description; that's
just the symptom. The problem is that your'e not separating the name
of the context from the name of the expectation. Try naming your
classes for the state of the world, and the tests for the exact thing
that you expect to happen. Like this:

class when_bar_connects_successfully:
    def foo_is_true(self):

I willfully violate PEP 8's capitalization rules in this case because
the camel casing gets too hard to read. You can teach Nose to run
tests like these with a sufficiently advanced -m. Expecter Gadget's
runtests.py does this, though it's a weaker form than the example
above. It's here:


More information about the testing-in-python mailing list