Can the filters from a mix test
be captured by the test_helper.exs
file?
I have an umbrella application in which one app has tests which run against an external API. In order for these tests to run, I need to refresh an access token from the external API. I only need to do this once before the entire test suite is run (not once per test).
It makes most sense to put this refresh function in the test_helper.exs
file of the app, but I only need to run it when I’m running the tests for the external API, which are disabled by default. Is there any way to do this?
My set-up for ExternalApi
app test_helper.exs
file
ExUnit.configure exclude: [:external_calls]
ExUnit.start()
if <some variable from mix> do
# Put a valid access token in the config.
refresh_token = Application.get_env(:external_api, :refresh_token)
case ExternalApi.Token.refresh(refresh_token) do
{:ok, resp} -> Application.put_env(:external_api, :access_token, resp.access_token)
{:error, _} -> nil
end
end