Is this a good way to implement testing

Ben Finney ben+python at benfinney.id.au
Sun May 3 04:52:21 EDT 2015


Peter Otten <__peter__ at web.de> writes:

> Be aware that there is also doctest which scans docstrings for text
> resembling interactive Python sessions. Doctests are both tests and
> usage examples, so I think it's good to put a few of these into the
> module.

Yes, it's definitely a good idea to put some examples into the
docstrings as doctests.

Be aware, though, that this is *not* a substitute for unit tests;
doctest is for testing your documentation, not testing your code.

You should not aim for extensive coverage in doctests. Heavy use of
doctests makes for bad tests *and* bad documentation.

Instead, write only those examples that the reader will find helpful to
understand normal usage; and use the ‘doctest’ module to test that your
documentation is still accurate.

Put all your other broad-coverage tests elsewhere (unit tests, behaviour
tests, etc.) and leave the docstrings readable.

-- 
 \          “Generally speaking, the errors in religion are dangerous; |
  `\    those in philosophy only ridiculous.” —David Hume, _A Treatise |
_o__)                                           of Human Nature_, 1739 |
Ben Finney




More information about the Python-list mailing list