[TIP] Docstrings in Test methods
Michael Foord
michael at voidspace.org.uk
Mon Nov 7 10:14:48 PST 2011
On 05/11/2011 13:05, Mike Pirnat wrote:
> I work in a pretty big codebase with a lot of developers. We prefer
> not having a docstring on our tests so that when they do fail, we can
> quickly identify what test it is (and who the best people to fix it
> are going to be).
>
> Our compromise in the sake of explaining a test is to use a comment
> where we would otherwise have a docstring in production code.
>
> I would be all for using docstrings for consistency with our
> production code if the test runner wouldn't replace the test
> module/class/method with the docstring in its output.
>
Output from unittest2 (and Python 2.7):
$ unit2 discover -v
test_something (test_thing.SomeTest)
This test has a docstring ... ERROR
======================================================================
ERROR: test_something (test_thing.SomeTest)
This test has a docstring
----------------------------------------------------------------------
Traceback (most recent call last):
File "/compile/temp/test_thing.py", line 7, in test_something
1/0
ZeroDivisionError: integer division or modulo by zero
----------------------------------------------------------------------
Ran 1 test in 0.022s
The docstring is still output in verbose mode - but *after* the test name.
Michael
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
More information about the testing-in-python
mailing list