Monkey Patching
say it: “MUNG-kee PACH-ing” /ˈmʌŋki ˈpætʃɪŋ/
Replacing a function or method while the program runs.
What is monkey patching?
Monkey patching means replacing a function or method while the program is running. It's handy in tests, but risky in real code because it changes behavior far from where you'd look.
import random
random.randint = lambda low, high: 6 # every dice roll is now 6
print(random.randint(1, 6)) # 6: fine in a test, confusing anywhere else
Level: Master · More Python terms at this level
Updated