What is the lifetime or scope of module attributes if declared before function definitions?

Should module attributes reset after every function definition or does ExUnit reset @tag with macros?

Would I need @doc false for second/0 if I had a @doc for first/0 and third/0?

defmodule MyApp do

  @tag 0

  @tag 1
  def first() do
    @tag |> IO.inspect() # prints 1
  end

  def second() do
    @tag |> IO.inspect() # prints 1
  end

  @tag 3
  def third() do
    @tag |> IO.inspect() # prints 3
  end

end

Excellent question. Module attributes are not reset by default.

However, if def or test “use” an attribute, then they also reset it. So def will use and reset any @doc. test will use and reset any @tag. Etc. In ExUnit, if you want to set a tag for everything, then you have @moduletag and @describetag.

2 Likes