kaocha

richiardiandrea 2025-04-02T19:52:02.752779Z

Hi all! Does anybody here have a favourite hook/way for closing a connection that has to be shared throughout the whole test?

richiardiandrea 2025-04-08T15:39:03.948929Z

yeah I am very familiar with those. The problem I am trying to solve is to start something (an embedded postgres instances - or a docker container for that matter) before the first test is run and stop that after the last test is run. When watching this really improves the runtime. I am relying now on dynamic bindings/atoms but I was exploring if kaocha adds hooks for that use case. Leaving it here in case others here have solved the same problem before or have advice, thanks!

2025-04-08T16:05:59.223519Z

for this i would recommend using component (or a similar DI library).

2025-04-08T16:08:40.002359Z

at a previous job, we had a set up where there was a *system* var in the main test entrypoint (all test files required it for the helper functions), and during load it would be populated with the database connections, and then we'd call (component/up *system*) and (component/down *system*) in a macro that wrapped other calls

richiardiandrea 2025-04-08T16:09:46.912469Z

yeah we use mount- we are doing that right now, the pre-load / post-load / wrap-run hook is what we are using but they are not "per full run" - they are per test

richiardiandrea 2025-04-08T16:09:51.864709Z

(or per suite)

2025-04-08T16:12:00.156539Z

i think kaocha supports this with the pre-run hook: https://cljdoc.org/d/lambdaisland/kaocha/1.91.1392/doc/10-hooks#config--test-plan-hooks

2025-04-08T16:12:21.071099Z

oh, you mean you're already using kaocha's pre-load hook? my apologies

richiardiandrea 2025-04-08T17:05:12.016389Z

yeah - we are already using that and it's not "global" if that makes sense

Ivar Refsdal 2025-04-07T08:59:33.427539Z

OK. I don't know about that. Are you familiar with fixtures? That is per test namespace (I think)

Ivar Refsdal 2025-04-03T09:07:27.125839Z

The whole test as in a single file or all test files?

Ivar Refsdal 2025-04-03T09:07:59.527929Z

Or just a single test inside a test file?

richiardiandrea 2025-04-03T19:24:26.125139Z

I basically want to close my db connection at the end of the tests