monkeygroover
Issue with ExUnit coloring
I have an issue since upgrading to Elixir 1.15, some of our tests that use capture log are failing because the output contains ansi color escape codes. I added the following before each ExUnit.start() in each app in the umbrella to try to fix this:
ExUnit.configure(
exclude: :skip,
formatters: [ExUnit.CLIFormatter, JUnitFormatter],
capture_log: true,
colors: [enabled: false]
)
however it is now not deterministically fixing it. some runs the tests pass, and some runs the tests fail with the escape codes. Are these settings per umbrella app, or is it possible they share some global state and depending on ordering there is a race somewhere?
Most Liked
monkeygroover
Yes, thank you, that helped. I’m not completely sure why i was seeing seemingly intermittent failures, but i’ve gone through and reviewed/updated all the logging settings to use the latest :default_formatter changes and then added using your suggested colors section in test and it’s all working nicely again. thanks.
eksperimental
You can use IO.ANSI.format(chardata, false) , convert it to a string and match on it.
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true) |> to_string()
"Hello, \e[31m\e[1mworld!\e[0m"
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], false)
[[[], "Hello, "], "world!"]
iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], false) |> to_string()
"Hello, world!"
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









