I’ve got a couple custom mix tasks that I call during various setup stages of my tests. Is there a way to run them so the info messages that they print to stdout are not returned?
Can you give an example of what is happening?
Sure – some of my test modules use
setup_all to refresh the database via some mix tasks, e.g.
defmodule MyApp.SomethingTest do use ExUnit.Case setup_all do # Reset the database Mix.Task.run("mongo.drop") Mix.Task.run("mongo.index") :ok end # ... tests follow ...
When I run
mix test, I see in the logs all the messages output by the mix tasks, e.g. from
Mix.shell().info("Mongo database dropped.")
I would prefer to execute those tasks “silently” so their messages don’t pollute the output of the test run.
You can change the current
Mix.shell() before running the commands.
Is this what you meant? Something like this?
setup_all do shell = Mix.shell() Mix.shell(Mix.Shell.Quiet) Mix.Task.run("noisy.task") Mix.shell(shell) # <-- return to previous shell :ok end