throw event ignores count task

Bug #634566 reported by Mark Hammond
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mocker
Fix Released
High
Gustavo Niemeyer

Bug Description

Adding a throw event causes the specified exception to be thrown an unlimited amount of times. This is different than other events which honour the implicit or explicit count task. For example:

from mocker import *
mocker=Mocker()
obj = mocker.mock()
obj.hello()
mocker.throw(RuntimeError("bah"))
mocker.replay()
for i in range(2):
    try:
        print obj.hello()
    except RuntimeError:
        print "failed", i

The code above prints the "failed" line twice. The expected (by me) behaviour is for the RuntimeError to be caught once, then an AssertionError be thrown as an implicit could of 1 is in effect. Adding an explicit count is also ignored.

The problem seems to be in Event.run - tracing through the code I see that the AssertionError has been recorded in 'errors', but the exception raised by the task causes the AssertionError to be lost. A reasonable patch would probably be to catch *all* exceptions raised by tasks, and only re-raise it when 'errors' is empty. The current behaviour could be maintained by using an explicit 'count' which would avoid prior errors being accumulated. If it is agreed this is indeed a bug, I'll attempt to put a patch and test case together.

Changed in mocker:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

That has been fixed in revision 70 in trunk, and will be in the next release.

Changed in mocker:
status: Confirmed → Fix Committed
Changed in mocker:
assignee: nobody → Gustavo Niemeyer (niemeyer)
milestone: none → 1.1
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.