is there a cannonical way to temporarily override certain aspects of Malli validation when writing unit tests? for example, when writing one specific unit test, I'd like to temporarily turn off (or modify) Malli validation for one specific funciton (e.g. a constructor), so that I can pass in a dummy value that would be considered underspecified in my real-world production setting, but is nonetheless useful for testing. i've come across this a few times, for example when running unification in https://github.com/hyperfiddle/rcf
There's also the :filters argument which looks a little nicer https://github.com/metosin/malli/blob/master/docs/function-schemas.md#defn-instrumentation
This macro seems useful
(defmacro with-unstrument [options & body]
`(let [options# ~options]
(try (mi/unstrument! options#)
(do ~@body)
(finally
(mi/instrument! options#)))))(with-unstrument
{:filters [;; everything from user ns
(mi/-filter-ns 'user)
;; ... and some vars
(mi/-filter-var #{#'power})
;; all other vars with :always-validate meta
(mi/-filter-var #(-> % meta :always-validate))]
;; scope
:scope #{:input :output}
;; just print
:report println}
(run-test))
I'm not aware of anything too slick, but the :data argument here lets you control which vars are instrumented https://github.com/metosin/malli/blob/52ea58a36ff5172b38dfc526ca638afa7226a4a0/src/malli/instrument.clj#L20
for example
(try (mi/unstrument {:data (select-keys (m/function-schemas)
['foo/bar])})
(run-test)
(finally
(mi/instrument {:data (select-keys (m/function-schemas)
['foo/bar])})))thanks ambrose! this worked for me, though I want to add two notes for people who stumble on this later • mi/unstrument --> mi/unstrument! • function schemas is a nested map of the form [:mapof :namespace [:mapof :symbol :malli-data]], so you need to select the keys sequentially, i.e.
{'foo (select-keys (get (m/function-schmeas) 'foo) ['bar]}
instead of
(select-keys (m/function-schemas) ['foo/bar])