[Freeipa-devel] [PATCH] 0024 Fix expected exception checking in tests

Petr Viktorin pviktori at redhat.com
Fri Mar 9 16:31:39 UTC 2012


Can you spot the bug in this test code?

try:
     do_invalid_operation()
except ExpectedError:
     pass


Our test suite had several of those.
Nose provides nice tools, `raises` (a decorator) and `assert_raises` (a 
context manager) that make checking expected exceptions a lot easier and 
less error-prone. This patch makes our tests use them.

If you didn't catch it, the error is that the test will pass when no 
exception is raised. Some of our tests handled that by adding an `else: 
assert False`, or an `assert False` at the end of the try block.
For consistency, the patch switches these correct ones to 
raises/assert_raises as well.

I've also uncovered and fixed a few test bugs that were hidden by this.

-- 
Petr³
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freeipa-pviktori-0024-Use-nose-tools-to-check-for-exceptions.patch
Type: text/x-patch
Size: 27068 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20120309/c46fa6c3/attachment.bin>


More information about the Freeipa-devel mailing list