You can use `Mix.env()` to do that today, if you want code to behave differently depending on the environment use it to conditionally define functions:
if Mix.env() == :test do def foo, do: IO.puts "Hello test" else def foo, do: IO.puts "Hello world!" end On Monday, December 17, 2018 at 11:41:19 PM UTC+7, [email protected] wrote: > > Very closely related to this, I've found myself multiple times lately > wanting to write code that differed between development/test and > production; mostly to introduce some function-call checks in the > development-like environments that would not be there in production to > improve speed. > > This is currently impossible to do without either: > - Depending on `Mix.env` existing, which breaks the library for anyone who > wants to build a release. > - Requiring manual configuration by the user of the library for each of > the environments. > > I feel like cases like this are common enough to warrant the > standardization of a way to check the current execution environment. > > > On Monday, December 17, 2018 at 11:49:39 AM UTC+1, boris kotov wrote: >> >> Hi all, >> >> when dealing with umbrella applications, you may need for some of the >> apps special env, for example a "e2e_test.exs" which is relevant for the >> web app, but not for all apps within the umbrella. >> In my case, I've an subapp, which has a special configuration for the >> "test" env. But because I had to uncomment import_config "#{Mix.env()}.exs" >> line, I also have to provide all the other possible config files for all >> possible env within my umbrella. I ended up by providing empty config >> files, to make it not fail. >> >> Proposal: >> >> import_config should not fail if config cannot be discovered, or provide >> an optional-flag, like `import_config("#{Mix.env()}.exs", optional: true)` >> so the config directory will stay clean only with configs you need for that >> particular application. >> >> Thanks! >> >> -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e7f4da52-9a9b-470f-ad9f-9c139479b31a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
