[TIP] RFF: Article on python test design pattern - DAI

Barry Warsaw barry at python.org
Tue Dec 8 07:28:01 PST 2009


On Dec 8, 2009, at 10:13 AM, Olemis Lang wrote:

> Hmmmm ... if something failed in your (unit)tests then it should be an
> exception condition (considering unittest philosophy and | or style
> since you write «positive» test cases i.e. conditions that have be
> asserted in to make the TC pass) . Isn't it ?

Something you might consider for more modern Pythons is to create a test exception hierarchy derived from BaseException instead of Exception.  Then common idioms like:

try:
   dotest()
except Exception:
   swallow()

won't catch the test assertion.  A bare except will, but those are (mostly) evil right? :)

Unfortunately AssertionError won't cut it for this since it has Exception in its parentage.

-Barry




More information about the testing-in-python mailing list