I have the following module that I am trying to write unit tests for.
import myModuleWithCtxMgr
def myFunc(arg1):
    with myModuleWithCtxMgr.ctxMgr() as ctxMgr:
        result = ctxMgr.someFunc()
    if result:
        return True, result
    return False, None
The unit tests I'm working on looks like this.
import mock
import unittest
import myModule as myModule
class MyUnitTests(unittest.TestCase):
    @mock.patch("myModuleWithCtxMgr.ctxMgr")
    def testMyFunc(self, mockFunc):
        mockReturn = mock.MagicMock()
        mockReturn.someFunc = mock.Mock(return_value="val")
        mockFunc.return_value = mockReturn
        result = myModule.myFunc("arg")
        self.assertEqual(result, (True, "val"))
The test is failing because result[0] = magicMock() and not the return value (I thought) I configured.
I've tried a few different variations of the test but I can't seem to be able to mock the return value of ctxMgr.someFunc(). Does anyone know how I might accomplish this?
Thanks!
 
    