Fork me on GitHub
#nbb
<
2022-10-22
>
alex21:10:14

I have a fixture with fixture-type :each set up for running Playwright tests in nbb. I'm trying to access the test name from within the fixture, but calling clojure.test/*testing-vars* from within the fixture function returns an empty list. Is that expected? Is there another way to get at the test name from within the fixture?

borkdude21:10:40

@rahx1t I tested this with CLJS and the result there is the same. There is also an open issue for JVM Clojure for this: https://clojure.atlassian.net/browse/CLJ-840 The way I usually solve this is via the report multimethod:

(require '[cljs.test :as t])

(defmethod t/report [::t/default :begin-test-var] [m]
  (println "====" (str  (ns-name *ns*) "/") (:name (meta (:var m)))))

(t/deftest foo
  (prn :foo))

(t/run-tests 'user)

alex21:10:22

Thanks for checking! Your suggestion above would allow us to access the test name within the t/report multimethod, but is there a way to get it from that multimethod into the fixture? Our use case is that we currently use fixtures to set up the browser instance for each test, and we store the browser instance inside of an atom that is then referenced from inside of the test. We're working on a way to parallelize tests, but that's failing at the moment. I suspect it might be due to tests running in parallel attempting to access the same browser instance stored inside of the atom. What I'd like to do is allow the fixture to store each test's browser instance within under its own keyed test-name After writing that out, I guess I'd also need to also figure out how to get the test name from within the test so I can access the correct browser from within the test. Makes me wonder if I should move away from a fixture for this use case and instead just use a setup function that i call before each test (https://stackoverflow.com/questions/31735423/how-to-pass-a-value-from-a-fixture-to-a-test-with-clojure-test)

alex21:10:45

Also I guess this is not an NBB issue, so I'd be happy to post somewhere more appropriate 🙂

borkdude22:10:14

Maybe try #clojurescript for now, I'm afk for some 💤 now, but if it works in CLJS but not in NBB, do let me know - and also keep me posted about whether you figured it out

thanks3 1
alex19:10:25

Unfortunately I didn't get any new info for us about accessing tests in fixtures

borkdude19:10:12

That's a pity. You could maybe write a custom deftest macro which saves the name somewhere

💡 1