throw event ignores count task
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.
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 |
Changed in mocker: | |
assignee: | nobody → Gustavo Niemeyer (niemeyer) |
milestone: | none → 1.1 |
status: | Fix Committed → Fix Released |
That has been fixed in revision 70 in trunk, and will be in the next release.