mock/patch os.path.exists with multiple return values
问题 I'm trying to test a function that I made that iterates through a list, and calls os.path.exists for each item in the list. My test is passing the function a list of 2 objects. I need os.path.exists to return True for one of them and False for the other. I have tried this: import mock import os import unittest class TestClass(unittest.TestCase): values = {1 : True, 2 : False} def side_effect(arg): return values[arg] def testFunction(self): with mock.patch('os.path.exists') as m: m.return