unittest: assertRaises() with an instance instead of a type

Ben Finney ben+python at benfinney.id.au
Thu Mar 29 03:55:13 CEST 2012

Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> (By the way, I have to question the design of an exception with error 
> codes. That seems pretty poor design to me. Normally the exception *type* 
> acts as equivalent to an error code.)

Have a look at Python's built-in OSError. The various errors from the
operating system can only be distinguished by the numeric code the OS
returns, so that's what to test on in one's unit tests.

 \              “In the long run, the utility of all non-Free software |
  `\      approaches zero. All non-Free software is a dead end.” —Mark |
_o__)                                                    Pilgrim, 2006 |
Ben Finney

More information about the Python-list mailing list