I am creating a resource during test setup based on a test's context (namely, its module and name):
However, I would also like to leave the resource in-place on test failure for inspection. (My prepare_resource function can handle the situation where a resource already exists on setup. This is opposite to the common tmpdir pattern where the resource cleans itself up automatically upon test conclusion but would have unexpected side effects if already setup.)
setup context do
prepare_resource_for_test_context(context) on_exit state do
case state do
{:failed, _} -> :ok
_ -> cleanup_resource_for_test_context(context)
end
end
end
Are there reasons to not entertain this functionality? Is there another way to accomplish it that doesn't rely on a test formatter to notice {:test_finished, test} and do the cleanup at a global level?
Implementation
Documentation could describe the optional callback parameter and elaborate that an on_exit callback defined in a setup_all would have some other behaviour (raise an error, receive nil or the case name instead of a state, etc—open to ideas).
Are would such an implementation be welcome?