I wish to be able to run the ExUnit tests multiple times from within a running process, such as iex
.
To do this I have code that looks somewhat like this:
def test do
# Unload test files
["test"]
|> Mix.Utils.extract_files("*")
|> Enum.map(&Path.expand/1)
|> Code.unload_files
# Reenable tasks
~w(loadpaths deps.loadpaths test)
|> Enum.map(&Mix.Task.reenable/1)
# Run the test suite
Mix.Task.run("test", args)
# Cleanup
:elixir_config.put(:at_exit, [])
end
This works, but prints the test/my_app/foo_test.exs:1 warning: redefining module FooTest
for each module defined in my test files.
I thought that as I had unloaded those files from the :elixir_code_server
these warnings would not be raised, but this is not the case.
How might I silence or avoid these warnings without resorting to methods such as silencing stderr?
It seems there is a compiler flag that I can use to suppress these warnings, but there is no clear public API for setting this flag. It seems we can disable these warning messages, there there is no clear API for doing so.
See elixir_compiler:get_opt/1
https://github.com/elixir-lang/elixir/blob/master/lib/elixir/src/elixir_compiler.erl#L8-L13
See elixir_module:check_module_availability/3
where it checks elixir_compiler:get_opt(ignore_module_conflict)
https://github.com/elixir-lang/elixir/blob/master/lib/elixir/src/elixir_module.erl#L408-L418
Ex <tab>
it won't show youExUnit
, because it is not loaded, but it is defined. If you typeExUnit.non_existent_fun
it will load theExUnit
and it will be in the shell. I think your best option would be to skip mix and run ExUnit directly. There is anrecompile
command in iex anyway, so you would only need to start the tests. – Brooke