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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews