Skip to content

Instantly share code, notes, and snippets.

@relaxdiego
Created July 3, 2012 08:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save relaxdiego/3038426 to your computer and use it in GitHub Desktop.
>>> from my_klass import my_klass
>>> from mocker import Mocker
>>> mocker = Mocker()
# Prepare the mock methods
>>> target = mocker.mock()
>>> target.method1(12) # doctest: +ELLIPSIS
<mocker.Mock object at ...>
>>> mocker.result(5)
>>> target.method2(12) # doctest: +ELLIPSIS
<mocker.Mock object at ...>
>>> mocker.result(7)
# Now use the mocked methods when testing method3
>>> mocker.replay()
>>> my_klass.method3.im_func(target, 12)
12
@relaxdiego
Copy link
Author

Not so keen on how method3 is called. Luckily, doctest is not the only option for Python unit testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment