Created
June 17, 2015 19:16
-
-
Save jmemich/bebe8c958504e1390501 to your computer and use it in GitHub Desktop.
mock test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.python.org/3/library/unittest.mock.html | |
from unittest.mock import MagicMock, Mock | |
from nose.tools import assert_equal, raises, assert_true, assert_raises | |
class A(): | |
def __init__(self): | |
self.item = 'item' | |
def return_item(self, thing = None): | |
if not thing: | |
return(self.item) | |
else: | |
return(thing) | |
class TestA(): | |
def __init__(self): | |
pass | |
def test_return_item(self): | |
# testing `MagicMock` for methods | |
t = A() | |
t.return_item = MagicMock(return_value = 3) | |
assert_equal(t.return_item('item'),3) ## TRUE | |
assert_equal(t.return_item(),3) ## TRUE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment