Skip to content
pbb.io/blog

TIL how to suppress log output in ExUnit tests

December 5, 2025
1 min read
Elixir

If a test triggers noisy log output, you can use ExUnit.CaptureLog.capture_log/2 to capture the noisy function:

import ExUnit.CaptureLog
test "logs a warning" do
log = capture_log(fn ->
MyApp.noisy_function()
end)
assert log =~ "something went wrong"
end

To silence logs for the whole test, use the @tag attribute:

@tag capture_log: true
test "something that logs warnings" do
assert MyApp.noisy_function() == :ok
end

Or enable it globally for all tests in test/test_helper.exs:

ExUnit.start(capture_log: true)

In all cases, if a test fails, the captured logs are included in the failure report.

Back to posts

Elixir
Phil-Bastian Berndt

Phil-Bastian Berndt
Tech Lead at Naymspace