[Proposal] ExUnit.before_suite/1

62 views
Skip to first unread message

João Ferreira

unread,
Feb 19, 2021, 6:57:53 AM2/19/21
to elixir-lang-core
Hey all,

I'd like to propose the complement to ExUnit.after_suite/1 which runs a set of callbacks immediately before the test suite starts.

We can set up code that's run before the test suite in test_helper.exs but, unlike ExUnit.after_suite/1, this code runs regardless of there being any actual tests to run as part of the suite. So if we need to tear down some code that was set up in test_helper.exs but no tests are run, we're out of luck.

Here's a particular example:
  1. Running an umbrella project with 2 apps
  2. mix test specific/file/in/app/1.ex
  3. Setup & tear-down happen correctly in app 1 suite
  4. Setup happens in app 2, but tear-down does not, because no files match the given path, and after_suite callbacks don't run.
Adding before_suite callbacks with the same semantics as after_suite would be helpful here, since setup would only happen if there were any tests to run.

Cheers,
João

José Valim

unread,
Feb 19, 2021, 8:07:45 AM2/19/21
to elixir-l...@googlegroups.com
Thanks for the proposal.

Perhaps it makes sense to run after_run in said cases as well. This way we can skip adding before_suite and make after_suite more consistent. WDYT?

--
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/884211ef-56dc-4a4b-b493-e8b67445e094n%40googlegroups.com.

Jon Rowe

unread,
Feb 19, 2021, 8:23:00 AM2/19/21
to elixir-lang-core
I would +1 always running after_suite if theres no before_suite. 

João Ferreira

unread,
Feb 19, 2021, 5:57:50 PM2/19/21
to elixir-lang-core
@José I thought about that at first but I think it means pulling the `after_suite` callback execution out from `ExUnit.Runner` into the main `ExUnit` module, and possibly calling the callbacks with no args, or empty stats, since when the mix task finds no files it exits with non-0 status and we end up here? I could be wrong, wasn't able to figure my way around the tests yet.

If the above is true this might be a more meaningful change, but happy to pursue it with guidance.

José Valim

unread,
Feb 20, 2021, 1:01:16 AM2/20/21
to elixir-l...@googlegroups.com
Yes, I think that’s the way to go. :) I willl be happy to answer questions!

Reply all
Reply to author
Forward
0 new messages