[TIP] Docstrings in Test methods

J. Cliff Dyer jcd at sdf.lonestar.org
Sat Nov 5 12:58:21 PDT 2011

On 11/05/2011 02:25 PM, Gary Bernhardt wrote:
> 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:
> https://github.com/garybernhardt/expecter/blob/master/runtests.py
> --
> Gary
> http://destroyallsoftware.com
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
Oh.  I kind of like that.  Never thought to name my test cases that 
way.  It makes sense to me in that it kind of specifies what you'd have 
in your setUp in a way that "UserActivationTestCase" doesn't.  I might 
have to start trying this naming convention.


More information about the testing-in-python mailing list