phtrivier
Should it be safe to use Application put/get env in multiple tests ?
Assuming I “clean” the env at the setup of each tests, is it possible that env “leaks” between tests ?
For example this seems to work, but is there any guarantee that it won’t fail once in a blue moon ?
defmodule SUT do
def act() do
x = Application.get_env(:app, :params)[:x]
# .... Use x for whatever
end
end
defmodule Case1 do
use ExUnit.Case
setup do
Application.put_env(:app, :params, x: nil)
end
test "Code that needs x to be 0" do
Application.put_env(:app, :params, x: 0)
SUT.act()
end
test "Code that needs x to be 1" do
Application.put_env(:app, :params, x: 1)
SUT.act()
end
end
defmodule Case2 do
use ExUnit.Case
setup do
Application.put_env(:app, :params, x: nil)
end
test "Code that needs x to be 3" do
Application.put_env(:app, :params, x: 3)
SUT.act()
end
end
(In particular, I’m not clear about whetever a Process is run for each test, for each case, etc… and how it might interact with Application config…)
Trending in Questions
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hubertlepicki
This will break as soon as you use
async: truein your tests. Which may or may not be a problem for you.You probably also want to do the cleanup after the tests, not before. If the tests run in random order, they will jump to some other test file after these tests are done, and the variables may be affecting the behavior in other tests. If you do the cleanups in
setupblocks executed before each test here, you want to do it in other test files as well. Otherwise weird things will happen.Alternative to this is to clean up in
on_exitcallback: ExUnit.Callbacks — ExUnit v1.20.2So you can go with what you have provided:
async: falseon_exitblockjtompl
If you want a code example for the above, it would be like this:
soyjeansoy
Wow this solved my problem!

axelson
If you use ProcessTree then you can effectively modify the application environment for most processes while keeping the ability to use
async: truetests. It works by looking for env first in the process dictionary of the current process, and then the dictionary of all ancestor and caller processes:https://github.com/jbsf2/process-tree
I’ve been using it quite a bit and it’s a really nice way to allow using the application environment while still using
async: true.