Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting to_return_value changes expectation checks #84

Closed
levidobson opened this issue Nov 13, 2019 · 1 comment · Fixed by #85
Closed

Omitting to_return_value changes expectation checks #84

levidobson opened this issue Nov 13, 2019 · 1 comment · Fixed by #85

Comments

@levidobson
Copy link

See the following examples. In both cases the mocked function gets called by the tested code.

self.mock_callable(
    mock_service, "func"
).for_call(expected_request).to_return_value(None).and_assert_called_once()
# passes, all good
self.mock_callable(
    mock_service, "func"
).for_call(expected_request).and_assert_called_once()
# error: UnexpectedCallReceived: <StrictMock ...>, 'function_name': Excepted not to be called!

I'm not sure if omitting to_return_value should be allowed or not, but it looks like the error message is a bit detached from the expectations anyway. The error message says Excepted not to be called! when clearly I have an .and_assert_called_once().

(Btw I just noticed there is a typo in the error message Excepted -> Expected.)

@fornellas
Copy link
Contributor

The error message is indeed misleading, but it is doing the right thing. Looking at

self.mock_callable(
    mock_service, "func"
).for_call(expected_request).and_assert_called_once()

you are telling the mock to accept a specific call, but not telling it what to do when this call is made. In this case, using and_assert_called_once() makes little sense, as the test would never pass, as the call can never succeed.

I just put #85 that makes this case a ValueError:

    1) ValueError: You must first define a behavior. Eg: self.mock_callable(target, 'func').to_return_value(value).and_assert_called_exactly(times)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants