softodrom

softodrom

Hi,

I have some compile env and I want to change their values in some specific test cases and then change them back.
Is there any way of doing that? recompile/1 is not working as this function simply recompiles Elixir modules, without reloading configuration, recompiling dependencies, or restarting applications.
I think that I need to reload the configuration too.

Best regards.

Showing Posts 1 to 10

Hermanverschooten

Hermanverschooten

How are you accessing their values?

D4no0

D4no0

You can use Application.put_env/3, however you need to be careful with asynchronous tests as application environment is global.

softodrom

softodrom OP

In config.exs config :app, :retry

softodrom

softodrom OP

I access them by using Application.compile_env/3

Hermanverschooten

Hermanverschooten

I assume as module variables @… then I think the only way to do it is to change them in test.exs.
As far as I know these are replaced during compilation by their respective values, so changing the config in a test will yield nothing. Though I must say I do not see a how a compile time variable could need to be changed in a test. If this is a variable that can change it should not be compile time.

softodrom

softodrom OP

There is no way to recompile the app during tests?

softodrom

softodrom OP

Application.put_env/3 does not change compile time variable

KristerV

KristerV

recompiling during tests doesn’t make sense. it’s the same as recompiling while a server is running.

feels like a XY problem. what are you actually trying to accomplish?

softodrom

softodrom OP

To test the usage of compile env variables. I have default values in case comp_env are not provided. I need to make a test case when I change their value

KristerV

KristerV

one option is to have separate config files, but then you would have to run with MIX_ENV=test_this mix test. does this solve it?

but what are you testing exactly? why are compile time variables changing?

i’m pretty sure you don’t need to test if compile time variables work, that’s elixir. you can trust elixir. you probably want to test what happens in your code with different values for that variable. in that case just hardcode the variable into the test. meaning ignore the env var and create a new one, then pass it into the function/process you’re testing.

if it turns out that your code uses the env var in the function you’re testing, well then make the value an argument in the function so the test can pass it in (which is usually a good idea in terms of good code anyway).

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews