Closed NoahTheDuke closed 1 year ago
Thanks for the issue report! One theoretically useful thing about our behavior is that you could use a fixture to throw a more meaningful exception. I'm not sure this theoretical use case is worth diverging from clojure.test
, though. Defining your own function or macro to wrap the problematic part probably makes more sense (or getting the bad fixture fixed).
(FYI for people stumbling upon this, you should use throws?
for tests that deliberately throw an exception.)
For future reference, here are the relevant bits of test.clojure
:
Thanks for linking to the clojure.test code, I should have done that to begin with!
In
clojure.test
, the functiontest-vars
callseach-fixture-fn
, wrapping callingtest-var
on each test function being run.test-var
wraps the test function in a try-catch, and if there's an error in the test, it reports an error directly. In other words,:once
and:each
fixtures don't see any exceptions thrown by the test becausetest-var
catches all exceptions and returnsnil
.kaocha
, on the other hand, wraps the test function in any:each
fixtures inkaocha.type.var
with the reduce call. Then the wrapped test is executed within the try-catch block, which means that the:each
fixtures see any thrown exceptions before thekaocha.type.var
try-catch can catch and report them.The result is that if an
:each
fixture catches and doesn't rethrow the exception, then no error is reported and the test is treated as successful.Reproduction below. If you use kaocha to run
nested-test
, you'll see that it outputs "once before", "each before", "each caught", and "once after", and shows 1 passing test with 1 assertion.