How to permanently mock return value of a function in python unittest
问题 I have a function # foo.py NUM_SHARDS = 10 def get_shard(shard_key: int) -> int return (shard_key % NUM_SHARDS) + 1 I want to mock this function such that whenever this function is called, it returns a certain value. I've tried patching like such # test.py @mock.patch('foo.get_shard', return_value=11) def testSomething(self, patched_func): patched_func() # >> 11 ... OK so this is fine but get_shard(4) # >> 5 .... Original impl being executed I want to deeply modify this function to always