Fl4m3Ph03n1x
Background
I have a test file with several describe blocks, each one with a custom setup block, like the following:
defmodule MyAppTest do
use ExUnit.Case
describe "group 1" do
setup do
:persistent_term.put("hello", :world)
:ok
end
test "test 1" do
assert true
end
test "test 2" do
assert true
end
end
# describe group2 ....
end
Here I am setting up a persistent term that I will use along the app. Now, once I reach the end of all tests in the describe block, I want to clean up, meaning I want to delete the "hello" entry from :persistent_term.
To achieve this I am aware of on_exit, but according to my understanding, this callback is only executed once at the end of all tests from all describe blocks.
Questions
- Is my understanding of
on_exitcorrect? - How can I run a clean up function after the tests of each
describeblock?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
on_exitin asetupblock is executed after each test, in my experience. I’ve never tried usingon_exitinsetup_allthough.Fl4m3Ph03n1x
According to my understanding and in my specific example,
setupwill only be executed once perdescribeblock. What I am looking for is aon_exitthat is executed once per describe block as well.josevalim
setupis always executed per test andon_exitwill always respect the context it is called in. On exit in setup runs after the test. On setup all, after all tests, etc.Fl4m3Ph03n1x
Ahh, so in my example, I am actually running
:persistent_term.put("hello", :world)each time I run a test, and not once per describe block, right?Will the current code run
:persistent_term.put("hello", :world)once per each test inside the givendescribeblock, or once per each test independently?josevalim
It will run once for each test in the describe block. But since it is a side-effect, it will be leaked to other tests.
Fl4m3Ph03n1x
I see. This open an interesting discussion (for another post).
Last set of questions:
setup_allinside adescribeblock, it will ignore it, correct? (meaning it will run as if it wasn’t inside a block, before all tests in the file)on_exitwith setup all? Could someone give me an example? (I have trouble understanding the docs)peerreynders
If I understand the source correctly it won’t even compile.
i.e. it doesn’t look like it is any different from using
on_exit/1inside a regularsetupblock.on_exitregisters a function to perform the teardown (and if the function is created inside the block is has access to anything inside of the block).