How can I turn off IO.puts in the test environment?

My app’s seeder IO.puts different messages so when the seeder is run, the user knows what’s happening. I also test one of the seeder functions because its seeding from a CSV and I want to ensure that it works in a few different edge cases. However, I don’t want to IO.puts these messages when tests are running. I don’t want to have to check the environment each time before IO.puts is run. How can I turn off IO.puts in the test environment?

1 Like

You could use Logger and in the test config set Logger to remove debug level messages. If you’re using Phoenix you probably already have it as a dependency.

https://hexdocs.pm/logger/Logger.html

4 Likes