I have a test file with several describe blocks, each one with a custom setup block, like the following:
defmodule MyAppTest do
describe "group 1" do
test "test 1" do
test "test 2" do
# describe group2 ....
Here I am setting up a persistent term that I will use along the app. Now, once I reach the end of all tests in the describe block, I want to clean up, meaning I want to delete the "hello" entry from :persistent_term.
To achieve this I am aware of on_exit, but according to my understanding, this callback is only executed once at the end of all tests from all describe blocks.
Is my understanding of on_exit correct?
How can I run a clean up function after the tests of each describe block?
If I understand the source correctly it won’t even compile.
Could someone give me an example?
i.e. it doesn’t look like it is any different from using on_exit/1 inside a regular setup block. on_exit registers a function to perform the teardown (and if the function is created inside the block is has access to anything inside of the block).