diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex
index e7f8d272c..e5c9c668b 100644
--- a/lib/pleroma/stats.ex
+++ b/lib/pleroma/stats.ex
@@ -23,6 +23,7 @@ defmodule Pleroma.Stats do
 
   @impl true
   def init(_args) do
+    if Pleroma.Config.get(:env) == :test, do: :ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo)
     {:ok, nil, {:continue, :calculate_stats}}
   end