Can you easily call an external module as an ExUnit setup block?

Many of my test files includes snippets like this:

import Mox

setup :verify_on_exit!

However, if I’m only importing mox so that I can directly call verify_on_exit! that feels like a hinderance to readability.

In my mind it would be nice if this worked:

setup &Mox.verify_on_exit!/1

But this results in the error: (ArgumentError) setup/setup_all expect a callback name as an atom or a list of callback names.

A working alternatives is:

setup :verify_on_exit!
defdelegate verify_on_exit!(context), to: Mox

Is there any better way than that?

How about this?

setup do
1 Like

Yeah that definitely does make sense.

Is there something you could do if you’re writing a helper that needs to register an on_exit callback? (I probably should’ve included some info on this in the original question)

I guess you could do something like

setup(context) do
  MyModule.register_verification(context, &on_exit/1)