Depreciation warnings make tests nearly unusable

About 8 months ago we updated a large project from Elixir 1.8 to 1.10.4 and from Phoenix 1.3.0 to 1.4.17.
Ever since then we get so many depreciation warnings in the test suite that it is actually difficult to read the tests. They are of all types:

.warning: the :headers option is deprecated, please use :skip_headers instead
  (nimble_csv 0.7.0) lib/nimble_csv.ex:330: NimbleCSV.RFC4180.parse_stream/2
warning: passing float to Decimal.new/1 is deprecated as floats have inherent inaccuracy. Use Decimal.from_float/1 or Decimal.cast/1 instead
  (decimal 1.9.0) lib/decimal.ex:1187: Decimal.new/1
  (ecto 2.2.12) lib/ecto/type.ex:587: Ecto.Type.cast/2
  (ex_machina 2.4.0) lib/ex_machina/ecto_strategy.ex:62: ExMachina.EctoStrategy.cast_value/3

Most of the warnings are related to Decimal.new/1 which I get and could be fixed by upgrading ex_machina and number but that leads to a whole other cascade of problems which I’m not equipped to handle right now.
Is there a way I can quite these logs for now?
I’ve tried updating the config/test.exs files with config :logger, level: :error and that dosen’t seem to do anything.

1 Like

The reason the config change doesn’t work is that those are compiler warnings not runtime warnings. As far as I know there is no way to disable the display of compile warnings.

2 Likes

If this is only in CI then you could run a prior step like MIX_ENV=test mix deps.compile, then your mix test output section will be much cleaner.

6 Likes

Thanks for the responses, unfortunately running MIX_ENV=test mix deps.compile does not clean up things when I test locally.
After looking closely at the warnings it seems about 90% originate with ExMachina:

warning: passing float to Decimal.new/1 is deprecated as floats have inherent inaccuracy. Use Decimal.from_float/1 or Decimal.cast/1 instead
  (decimal 1.9.0) lib/decimal.ex:1187: Decimal.new/1
  (ecto 2.2.12) lib/ecto/type.ex:587: Ecto.Type.cast/2
  (ex_machina 2.7.0) lib/ex_machina/ecto_strategy.ex:72: ExMachina.EctoStrategy.cast_value/3
  (ex_machina 2.7.0) lib/ex_machina/ecto_strategy.ex:58: anonymous fn/2 in ExMachina.EctoStrategy.cast_all_fields/1
  (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
  (ex_machina 2.7.0) lib/ex_machina/ecto_strategy.ex:49: ExMachina.EctoStrategy.cast/1
  (ex_machina 2.7.0) lib/ex_machina/ecto_strategy.ex:25: ExMachina.EctoStrategy.handle_insert/2
  (elixir 1.10.4) lib/stream.ex:1355: Stream.do_repeatedly/3
  (elixir 1.10.4) lib/enum.ex:2789: Enum.take/2
 ...controller_test.exs

Which is odd to me, I am using ExMachina 2.7.0. Do I need to update Ecto as well?

Bumping phoenix_ecto from 3.0 to 3.6.0 seems to have fixed the issue there. I started down that route last week but I kept running into dependency issues, I must have just grabbed the perfect version or inadvertently fixed something else.

1 Like

Just for reference, mix hex.outdated is a helpful way to show dependencies that are out of date.

4 Likes

mix test --trace --seed 0 to run them one by one, in a non-random deterministic way. You can pick the issues out one by one.

2 Likes