1

I have a module of tests that run synchronized one after the other.
I would like to clean all the changes done on the db by the tests after all tests complete, i.e. I want the data to persist in the db between one test to another.
My app is using a PostgreSQL database (MyRepo).
when I use Ecto.Adapters.SQL.Sandbox.checkout(MyRepo) in the setup_all function the DB gets cleaned after each test.
This is my condig/test.exs file:

config :my_repo, MyRepo,
       pool: Ecto.Adapters.SQL.Sandbox,
       database: "my-repo-test",
       username: "postgres",
       password: "postgres",
       hostname: "localhost",
       port:     "5432",
       pool_size: 1,
       max_overflow: 0,

What is the right way to do it?

Andrei Dragotoniu
  • 6,155
  • 3
  • 18
  • 32
fay
  • 2,086
  • 2
  • 14
  • 36

1 Answers1

2

You might use ExUnit.Callbacks.on_exit/2:

setup_all do
  on_exit fn -> Repo.cleanup() end
end
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160