Protocol has already been consolidated (in tests)

Hello,

I have the following piece of code in tests:

defmodule DefTest do
  use ExUnit.Case

  defimpl Enumerable, for: __MODULE__ do
    def reduce(map, acc, fun) do
      1
    end

    def member?(_map, _other) do
      {:ok, false}
    end

    def count(map) do
      1
    end
  end

  test "greets the world" do
    assert Def.hello() == :world
  end
end

and mix test emits warning:

warning: the Enumerable protocol has already been consolidated, an implementation for DefTest has no effect
  test/def_test.exs:4

What can I do ? The possible solution will be to put the test-class with protocol implementatition into lib folder. That works, but I hope there can be better solution.

Thanks!

Disable consolidation for test environments.

consolidate_protocols: Mix.env != :test

In your project config should do it.

3 Likes