[TIP] Asserting behaviour of exception tracebacks

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Jan 30 22:30:27 PST 2008


Ben Finney <ben at benfinney.id.au> writes:

>     class ModuleSpecificError(RuntimeError):
>         def __init__(self, orig, context):
>             self.orig = orig
>             self.context = context
> 
>         def __str__(self):
>             orig_name = orig.__class__.__name__
>             msg = (
>                 "failed during %(context)s"
>                 " (%(orig_name)s: %(orig)s)"
>                 ) % vars(self)

Clearly the construction and returning of the 'msg' in that '__str__'
method needs to be fixed. That's merely an artefact because I made the
example for this post. Hopefully its intent is clear enough to
understand the point of the rest of the post.

-- 
 \        "If you go parachuting, and your parachute doesn't open, and |
  `\        you friends are all watching you fall, I think a funny gag |
_o__)             would be to pretend you were swimming." —Jack Handey |
Ben Finney




More information about the testing-in-python mailing list