[Python-Dev] Unittest PEP do's and don'ts (BDFL pronouncement) (original) (raw)

Andrew Bennetts andrew-pythondev at puzzling.org
Thu Jul 17 02:22:52 CEST 2008


Michael Foord wrote:

Raymond Hettinger wrote: [...]

If some people want to proceed down the path of "useful additions", I challenge them to think bigger. Give me some test methods that improve my life. Don't give me thirty ways to spell something I can already do. I assert that... the following changes do meet those conditions: assertRaisesWithMessage - for testing the error messages from library functions, where the error message is part of the API under test (I'm less convinced with the need for a regex matching version myself.)

This one is easily solved by making assertRaises return the exception it caught. e.g.:

exc = self.assertRaises(AttributeError, getattr, foo, 'bar')
self.assertEqual("'Foo' object has no attribute 'bar'", exc.message)

At least Twisted and bzr have already made this exact change. It requires no new methods, and is more flexible than the proposed assertRaisesWithMessage.

-Andrew.



More information about the Python-Dev mailing list