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

Petr Viktorin pviktori at redhat.com
Fri Mar 16 12:59:02 UTC 2012


On 03/15/2012 10:36 PM, Rob Crittenden wrote:
> Petr Viktorin wrote:
>> 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.
>>
>
>
> test_1a_automountmap_add_indirect() was failing, checking for the wrong
> exception.

Silly me. Thanks for catching this.

> I also suggest using @raises for clarity in another spot. Here are my
> suggested changes:
>

Attaching updated patch.



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


More information about the Freeipa-devel mailing list