Understanding why (kaocha.repl/run 'my.ns-test) doesn't run my tests

Goal

I want to use kaocha.repl to run tests inside a library.

The REPL has been started from an application that uses the library with a :local/root dependency.

kaocha.repl/run not running what I expect

I was surprised that Kaocha didn’t run my namespace. The following happens in my REPL:

(require 'kaocha.repl)
(deftest wtf (is false))
(-> *ns* str symbol)
;; => terra.assetwatch-test

(kaocha.repl/run 'terra.assetwatch-test {:kaocha/fail-fast? true})
;; => WARNING: Did not load a configuration file and using the defaults.
;;    This is fine for experimenting, but for long-term use, we recommend creating a configuration file to avoid changes in behavior between releases.
;;    To create a configuration file using the current defaults and configuration file location, create a file named tests.edn that contains '#kaocha/v1 {}'.
;;    WARNING: All 22 tests were skipped. Check for misspelled settings in your Kaocha test configuration or incorrect focus or skip filters.
;;    WARNING: Test run exited with code 0
;;    0

Context

I jacked my REPL into an application, which uses a library with a :local/root dependency. This in my current working directory not being a root folder for the file I’m evaluating code in.

(require 'babashka.fs)

(str (babashka.fs/cwd))
;; => "/Users/teodorlu/repo/teodorlu/play.teod.eu"

*file*
;; => "/Users/teodorlu/repo/teodorlu/terra/test/terra/assetwatch_test.clj"
(kaocha.repl/config)
;; => e[33mWARNING: e[mDid not load a configuration file and using the defaults.
;;    This is fine for experimenting, but for long-term use, we recommend creating a configuration file to avoid changes in behavior between releases.
;;    To create a configuration file using the current defaults and configuration file location, create a file named tests.edn that contains '#kaocha/v1 {}'.
;;    {:kaocha.plugin.randomize/seed 2085742826,
;;     :kaocha.plugin.randomize/randomize? true,
;;     :kaocha/reporter [kaocha.report/dots],
;;     :kaocha/color? true,
;;     :kaocha/fail-fast? false,
;;     :kaocha/plugins
;;     [:kaocha.plugin/randomize
;;      :kaocha.plugin/filter
;;      :kaocha.plugin/capture-output],
;;     :kaocha/tests
;;     [{:kaocha.testable/type :kaocha.type/clojure.test,
;;       :kaocha.testable/id :unit,
;;       :kaocha/ns-patterns ["-test$"],
;;       :kaocha/source-paths ["src"],
;;       :kaocha/test-paths ["test"],
;;       :kaocha.filter/skip-meta [:kaocha/skip]}],
;;     :kaocha.plugin.capture-output/capture-output? true}

(kaocha.repl/test-plan) produces a test-plan that does not reference terra.assetwatch-test. It’s big, so I’ll refrain from inlining it here.


I really just want the tests to run, I’m happy to call a different Kaocha API function if I’m calling the wrong function.

Any advice appreciated! Let me know if a minimal reproduction is desired.

The tests are running if I add the library’s test folder to the application’s tests.edn:

;; /Users/teodorlu/repo/teodorlu/play.teod.eu/tests.edn
#kaocha/v1
{:tests
 [{:id :tplay
   :test-paths ["test"]}
  {:id :terra
   :test-paths ["../../teodorlu/terra/test"]}]}

It appears kaocha.repl/run calls into general machinery that requires a test plan, and that test plan requires explicit test paths. I was hoping that since I provided an explicit namespace that’s already been loaded, It wouldn’t require a test plan!

Unfortunately it does. From kaocha’s POV that “namespace” is just the identifier of a test, which it uses to filter the tests in the test-plan. That way the machinery is generic, for other test types “namespace” might not even be a useful concept.

1 Like