[TIP] Docstrings in Test methods

Alfredo Deza alfredodeza at gmail.com
Sat Nov 5 06:07:59 PDT 2011

On Sat, Nov 5, 2011 at 9:05 AM, Mike Pirnat <mpirnat at gmail.com> 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.

But this would be for failing tests you say? This is what I would see
in Python2.6
and unittest 1.63

$ python test_foo.py
FAIL: when foo uses bar as a connection it should be True when successful
Traceback (most recent call last):
  File "test_foo.py", line 7, in test_foo_should_be_true
    assert False

Ran 1 test in 0.000s

The test method *does* appear. Is this *not* the case in your code base?
> --
> Mike Pirnat
> mpirnat at gmail.com
> http://www.pirnat.com/

More information about the testing-in-python mailing list