This will break as soon as you use async: true
in your tests. Which may or may not be a problem for you.
You probably also want to do the cleanup after the tests, not before. If the tests run in random order, they will jump to some other test file after these tests are done, and the variables may be affecting the behavior in other tests. If you do the cleanups in setup
blocks executed before each test here, you want to do it in other test files as well. Otherwise weird things will happen.
Alternative to this is to clean up in on_exit
callback: https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#on_exit/2
So you can go with what you have provided:
- the tests are
async: false
- the cleanup is done in
on_exit
block