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

Fail mock_callable / mock_constructor configuration if it already received a call #16

Closed
fornellas opened this issue Apr 16, 2019 · 0 comments · Fixed by #241
Closed
Labels
easy enhancement New feature or request help wanted Extra attention is needed mock_constructor

Comments

@fornellas
Copy link
Contributor

By design, mock_callable() should be used like this:

self.mock_callable(target, 'attr')\
  .for_call(something)\
  .to_return_value(None)\
  .and_assert_called_once()
do_target_attr_call()

But sometimes people misuse it like:

mock = self.mock_callable(target, 'attr')\
  .for_call(something)\
  .to_return_value(None)
do_target_attr_call()
mock.and_assert_called_once()

Although this works right now, it is highly undesirable, as this undocumented usage pattern blocks implementation of #3, which can allow unexpected calls to fail on the spot, not after the test finishes.

Let's make mock_callable / mock_constructor fail if it is attempted to receive extra configuration, after it received the first call, which should prevent and educate users on this.

@fornellas fornellas added enhancement New feature or request help wanted Extra attention is needed labels Apr 16, 2019
@fornellas fornellas added this to the mock_constructor milestone Apr 9, 2020
@fornellas fornellas removed this from the mock_constructor milestone Apr 9, 2020
@fornellas fornellas added the easy label Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy enhancement New feature or request help wanted Extra attention is needed mock_constructor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant