Fork me on GitHub
#kaocha
<
2021-05-06
>
richiardiandrea18:05:32

Hi there, if I wanted to bootstrap a docker container for every suite would this work?

:kaocha/pre-load-test [com.cohesic.acuity.test/sql-test-container-start-hook]
          :kaocha/pre-test [com.cohesic.acuity.test/reset-script-run-each-leaf-hook]
          :kaocha/post-load-test [com.cohesic.acuity.test/sql-test-container-stop-hook]
I am using hierarchy/suite? for filter but I was wondering if the :pre-load-test is a good hook. I am on 1.0.726 at the moment.

richiardiandrea21:05:24

asking because (kaocha.hierarchy/leaf? testable) was returning false all the time I basically have to use (= (:kaocha.testable/type testable) :kaocha.type/var) with

:kaocha.hooks/pre-test [com.cohesic.acuity.test/sql-test-container-start-hook
                                  com.cohesic.acuity.test/run-setup-script-each-test-hook]
          :kaocha.hooks/post-test [com.cohesic.acuity.test/run-drop-script-each-test-hook
                                   com.cohesic.acuity.test/sql-test-container-stop-hook]

richiardiandrea21:05:33

actually, no that does not work either

richiardiandrea23:05:22

maybe I am misunderstanding something but if I call

clojure -M:test -m kaocha.runner unit --watch
I would expect to see only the :kaocha.testable/id :unit in the hook, is that a wrong assumption? I see all the suites passed in and I cannot differentiate which one is being run right now

plexus05:05:14

you will always get all testables passed in, but some will be marked as skipped

plexus05:05:35

I would use pre-run and post-run to start/stop the container, and pre-test to reset it

plexus05:05:53

(hierarchy/leaf? {:kaocha.testable/type :kaocha.type/var})
;; => true

richiardiandrea05:05:37

Thanks yes that now makes sense...and well I was trying another route now (kinda late here) to use wrap-run That works, except my test has an :each fixture that uses a dynamic var. I do binding in wrap-run but for some reason it arrives nil within the test fixture

richiardiandrea05:05:17

if fixtures are loaded at "load time" probably that is why I can't seem to make this work

richiardiandrea05:05:52

anyways thank you for your explanation!

richiardiandrea16:05:30

@U07FP7QJ0 How do you recommend checking if a test suite is "skipped"

richiardiandrea16:05:39

is there an api for that?

richiardiandrea18:05:27

Leaving this here if useful to some

(defn skipped-testable?
  [testable id]
  (let [desired-key-fn (juxt :kaocha.testable/skip :kaocha.testable/id)
        skip+test-id-tuple (desired-key-fn testable)]
    (= [true id] skip+test-id-tuple)))

(defn skipped-test-suite?
  [test-plan id]
  (some #(skipped-testable? % id) (:kaocha.test-plan/tests test-plan)))
Works against version 1.0.726

💯 4
richiardiandrea18:05:27

Leaving this here if useful to some

(defn skipped-testable?
  [testable id]
  (let [desired-key-fn (juxt :kaocha.testable/skip :kaocha.testable/id)
        skip+test-id-tuple (desired-key-fn testable)]
    (= [true id] skip+test-id-tuple)))

(defn skipped-test-suite?
  [test-plan id]
  (some #(skipped-testable? % id) (:kaocha.test-plan/tests test-plan)))
Works against version 1.0.726

💯 4