Elixir: Dialyzer warning `Function ExUnit.Callbacks.on_exit/1 does not exist`

Created on 6 Mar 2019  路  2Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
    Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
    Elixir 1.8.1 (compiled with Erlang/OTP 21)

  • Operating system:
    Linux Mint 19 and Ubuntu 14.04.5 LTS

Current behavior

When I run MIX_ENV=test mix dialyzer, I'm seeing a warning that Function ExUnit.Callbacks.on_exit/1 does not exist.

This happened after I added an on_exit call to the setup macro in a shared test case created using ExUnit.CaseTemplate.

So, the following test case template does not raise this warning:

defmodule MyApp.ConnCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Phoenix.ConnTest
      import MyApp.Router.Helpers

      @endpoint PotionProxyWeb.Endpoint
    end
  end

  setup _tags do
    {:ok, conn: Phoenix.ConnTest.build_conn()}
  end
end

But the following does raise that warning:

defmodule MyApp.ConnCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Phoenix.ConnTest
      import MyApp.Router.Helpers

      @endpoint PotionProxyWeb.Endpoint
    end
  end

  setup _tags do
    on_exit(fn -> IO.puts("CALLED") end)

    {:ok, conn: Phoenix.ConnTest.build_conn()}
  end
end

The warning then goes away when I move the setup block inside of the quote block that's part of the using macro, like this:;

defmodule MyApp.ConnCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Phoenix.ConnTest
      import MyApp.Router.Helpers

      @endpoint PotionProxyWeb.Endpoint

      setup _tags do
        on_exit(fn -> IO.puts("CALLED") end)

        {:ok, conn: Phoenix.ConnTest.build_conn()}
      end
    end
  end
end

All three versions of this work just fine when running my tests, by the way.

Most helpful comment

It was the PLT! Once I added :ex_unit to my dialyzer config like this:

dialyzer: [
  plt_add_apps: [:mix, :distillery, :ex_unit],
  check_plt: true,
  ignore_warnings: "dialyzer_ignore.exs"
]

the warning went away with the code that previously was giving me a
warning.

All 2 comments

I think this is rather an issue with your .plt. Could they have been built
without ExUnit? A quick way to check Is to add :ex_unit under

:extra_applicarions.

Jos茅 Valim
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

It was the PLT! Once I added :ex_unit to my dialyzer config like this:

dialyzer: [
  plt_add_apps: [:mix, :distillery, :ex_unit],
  check_plt: true,
  ignore_warnings: "dialyzer_ignore.exs"
]

the warning went away with the code that previously was giving me a
warning.

Was this page helpful?
0 / 5 - 0 ratings