“I have a confession. Even as the author of a public domain
Python library in fairly wide use, I have been far less than
systematic in including unit tests for my modules. In fact, the
bulk of those tests that are included in Gnosis Utilities fall
under gnosis.xml.pickle, and were written by a contributor to that
subpackage. I have found that the large majority of third-party
Python packages I download also lack a thorough unit test
collection.“Moreover, the tests that exist in Gnosis Utilities suffer from
another flaw: you often need to understand the expected output in a
fair amount of detail to even know whether a test succeeds or
fails. What passes as tests are actually — in many cases — more
like small utilities that utilize parts of the library. These tests
(or utilities) allow input from arbitrary data sources (of the
right type) and/or output in descriptive data formats. These test
utilities are actually rather useful when you need to debug some
subtle error. But as self-explanatory sanity checks of changes
between library versions, these kinds of tests do not succeed.“In this installment, I try to improve the tests in my utility
collection using the Python standard library modules doctest and
unittest, and I walk you through my experience (with a few pointers
on best approaches)…”
developerWorks: Testing Frameworks in Python
By
Get the Free Newsletter!
Subscribe to Developer Insider for top news, trends, & analysis