> 1. We should avoid mutating the global state in tests
The reason I'm proposing this is exactly with this in mind, to not really 
set the env variables but have it set inside the with_env scope.
This way multiple test can be run in parallel and no cleanup is required.
> 2. We should avoid reading system environment variables in code (use 
config/runtime.exs instead)
This is sometimes required - we use it for example to parametrize tasks 
that run inside kubernetes pods. 
It may be also useful to test the config
On Wednesday, March 27, 2024 at 9:26:51 PM UTC José Valim wrote:

> I don't see a strong need to make this part of ExUnit, especially because:
>
> 1. We should avoid mutating the global state in tests
> 2. We should avoid reading system environment variables in code (use 
> config/runtime.exs instead)
>
> Those can add to their own suites if necessary. :)
>
> On Wed, Mar 27, 2024 at 4:14 PM Daniel Kukula <danie...@gmail.com> wrote:
>
>> Currently, tests that use env variables can't be run async because the 
>> environment is shared. My proposal is to introduce a with_env function that 
>> will accept a function to execute and a mapping of params that the 
>> functions in System will accept as env variables:
>> Now: System.put_env("PORT", "4000")
>> assert some logic
>> System.delete_env("PORT")
>>
>> after
>>
>> with_env(%{"PORT" => "4000}, fn -> 
>> assert some logic
>> end) 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/3e7dcf24-ae69-47b0-a7b5-281055c70726n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/3e7dcf24-ae69-47b0-a7b5-281055c70726n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/ce013e9b-32c5-42bd-bc85-19bdb67134f2n%40googlegroups.com.

Reply via email to