Given the following:
class toTest(object)
def createObject(self):
self.created = toCreate()
class toCreate(object):
def __init__(self):
pass
# testFile.py
import unittest
class TestThing(unittest.TestCase):
def testCreated(self):
creator = toTest()
toTest.createObject()
# -- Assert that the 'toCreate' object was in fact instantiated
...how can I ensure that toCreate was in fact created? I have tried the following:
def testCreated(self):
created = MagicMock(spec=toCreate)
toTest.createObject()
created.__init__.assert_called_once_with()
But I get the following error: AttributeError: Mock object has no attribute 'init'. Am I misusing the MagicMock class, and if so how?