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

Make idempotent subout calls #21

Open
ivancrneto opened this issue Jan 6, 2024 · 0 comments
Open

Make idempotent subout calls #21

ivancrneto opened this issue Jan 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ivancrneto
Copy link
Owner

Idea:

def stubout_if_needed(mox_obj, parent_object, attribute):
  """Stubs out the call only if it's not already a mock."""
  if not isinstance(getattr(parent_object, attribute),
                    (mox.MockAnything, mox.MockObject)):
    mox_obj.stubout(parent_object, attribute)

Then if I want to set multiple expectations on the thing that I'm stubbing
out, I can safely call stubout_if_needed(self.mox, module, 'FunctionName')
each time before setting an expectation, and not worry about whether it's
already been stubbed out or not.

Combined with using mox.MoxTestBase which will unset all stubs in self.mox,
this seems pretty safe, because things will succeed whether I create and
use the stub or don't.

@ivancrneto ivancrneto added the enhancement New feature or request label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant