Ecto.Sandbox does not work with tests that have setup_all function

One situation when you do want this is if RbacUser has a unique index on that user ID - inserting that record in a setup block (inside a transaction) will block any other test that also inserts that record in a setup block, causing mayhem with async: true tests.

I’m not sure setup_all blocks run early enough for that, though. I’ve used code in test_helper.ex to insert records before the sandbox is started:

# generated by Phoenix
ExUnit.start()

# add insert statements here

# generated by Phoenix
Ecto.Adapters.SQL.Sandbox.mode(YourAppNameHere.Repo, :manual)

The other side-effect of this approach is that the test database has records in it at the end, since those initial inserts aren’t inside a transaction. You can either live with those (and change the inserts to be find-or-inserts) or reset the DB on every test run.