class FileIOTestCase(unittest.TestCase):
    """ For testing code involving file io operations """

def setUp(self):
    """ patches the open function with a mock, to be undone after test. """
self.mo = mock_open()
patcher = patch('builtins.open', self.mo)
patcher.start()
self.addCleanup(patcher.stop)

def get_written_string(self):
    return ''.join(c[0][0] for c in self.mo.return_value.write.call_args_list)
How to fix mock_open differences in calls but not in end result