Application.put_env/4 not persisted during tests

I’m trying to override some configurations prior to running integration tests in my umbrella app. I’m using mocks for my unit tests, but want to use my “live” modules for integration tests. The default configurations are stored in the dev.exs and test.exs config files. Before running the integration test I use Application.put_env/4 to set the “live” configuration (including the :persistent option), but when I inspect the configuration during the test, it shows the mocks are being used (the integration tests are failing).

Is this a run vs. compile time thing? I’ve had to run mix compile in the past to get changes to my config files to persist when I start my application.

Here’s a timely article on this very thing, but I can’t set the module explicitly in the test they way they do in the article, I need to rely on the configuration.

Turns out that the configurations are being persisted correctly. However, you cannot access overridden configurations using module variables because they are set at compile time and thus will not reflect Application.put_env/4 changes made at runtime.

So there’s no way to test based on wrong config values? Seems weird.

That isn’t what’s being said. Rather, you should avoid setting module attributes with config values you want to change at runtime.

1 Like

Oh, I see. Thanks for clearing that up.