Simple example:
def test():
with expect(xyz, times=1).abc().thenReturn(1, 2):
func_that_uses_abc_once()
This produces different, seemingly contradictory error messages.
times=0 or between=(0,0) results in e.g. "Wanted between: [0, 0], actual times: 1"
times=1 or between=(1,1) results in "Unused stub: abc()"
times=2 or between=(2,0) results in e.g. "Wanted between: [2, inf], actual times: 1"
After all, how can times=0 say it was executed once, but times=1 says it is unused?
Just to be clear, I am fully aware that thenReturn(1, 2) is the issue 😄 but the error message led me down a rabbit hole around times=1 rather than around thenReturn
Given the len(answers) part in the mockito codebase, maybe a clearer message can be produced if times (and the others) do not match the answer count?
I imagine due to all the chaining that one can do (e.g. .thenReturn(x).thenRaise(y).thenReturn(a, b)) this isn't an easy problem to solve, but if the check_used error message is more clear then one can self-diagnose very quickly.
Maybe something like
Unused stub: .abc(), which also has unused answers?
Once again thank you for the wonderful library!
Simple example:
This produces different, seemingly contradictory error messages.
times=0orbetween=(0,0)results in e.g. "Wanted between: [0, 0], actual times: 1"times=1orbetween=(1,1)results in "Unused stub: abc()"times=2orbetween=(2,0)results in e.g. "Wanted between: [2, inf], actual times: 1"After all, how can
times=0say it was executed once, buttimes=1says it is unused?Just to be clear, I am fully aware that
thenReturn(1, 2)is the issue 😄 but the error message led me down a rabbit hole aroundtimes=1rather than aroundthenReturnGiven the
len(answers)part in the mockito codebase, maybe a clearer message can be produced iftimes(and the others) do not match the answer count?I imagine due to all the chaining that one can do (e.g.
.thenReturn(x).thenRaise(y).thenReturn(a, b)) this isn't an easy problem to solve, but if thecheck_usederror message is more clear then one can self-diagnose very quickly.Maybe something like
Unused stub: .abc(), which also has unused answers?Once again thank you for the wonderful library!