I'd like to patch some elisp functions inside my unit tests. I've tried cl-labels
and cl-flet
, but neither achieve the result I want:
(defun return-number ()
1)
(defun calls-return-number ()
(return-number))
(defun patch-cl-labels ()
(cl-labels ((return-number () 2))
(calls-return-number)))
(message "After patching: %s" (patch-cl-labels))
I've looked at monkey-patching a functionmonkey-patching a function (but this permanently changes behaviour) and patching a third-party functionpatching a third-party function (this uses advice and holds on to the old function).