Skip to content

*ns* is never bound to the test namespace - #133

Open
danielsz wants to merge 1 commit into
talios:developfrom
danielsz:develop
Open

*ns* is never bound to the test namespace#133
danielsz wants to merge 1 commit into
talios:developfrom
danielsz:develop

Conversation

@danielsz

@danielsz danielsz commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

The test runner script is src/main/resources/default_test_script.clj. It runs in the com.theoryinpractise.clojure.testrunner namespace and calls (require ns) followed by (run-tests ns) for each discovered test namespace.

The bug: ns is never bound to the test namespace before run-tests is called. While deftest functions carry their own namespace at definition time (so symbol resolution within test bodies generally works), ns remains set to com.theoryinpractise.clojure.testrunner throughout. This breaks:

  1. Tests that read ns directly (e.g., (is (= 'my.ns (ns-name ns))))
  2. Tests using resolve, intern, find-var with unqualified symbols
  3. Tests that eval, load-string, or read-string code
  4. test-ns-hook functions that depend on ns being correct

Single file to change: src/main/resources/default_test_script.clj Wrap all three (run-tests ns) calls with (binding [ns (the-ns ns)] ...)

This is a small, targeted fix that's consistent with how other Clojure test tools handle namespace context.

The fix ensures that ns is bound to the correct test namespace when run-tests executes, so tests that use resolve, intern, ns directly, or other namespace-sensitive operations get the correct namespace context instead of com.theoryinpractise.clojure.testrunner.

The test runner script is src/main/resources/default_test_script.clj.
It runs in the com.theoryinpractise.clojure.testrunner namespace and
calls (require ns) followed by (run-tests ns) for each discovered test
namespace.

The bug: *ns* is never bound to the test namespace before run-tests is
called. While deftest functions carry their own namespace at
definition time (so symbol resolution within test bodies generally
works), *ns* remains set to com.theoryinpractise.clojure.testrunner
throughout. This breaks:

1. Tests that read *ns* directly (e.g., (is (= 'my.ns (ns-name *ns*))))
2. Tests using resolve, intern, find-var with unqualified symbols
3. Tests that eval, load-string, or read-string code
4. test-ns-hook functions that depend on *ns* being correct

Single file to change: src/main/resources/default_test_script.clj
Wrap all three (run-tests ns) calls with (binding [*ns* (the-ns ns)]
...)

This is a small, targeted fix that's consistent with how other Clojure
test tools handle namespace context.

The fix ensures that *ns* is bound to the correct test namespace when
run-tests executes, so tests that use resolve, intern, *ns* directly,
or other namespace-sensitive operations get the correct namespace
context instead of com.theoryinpractise.clojure.testrunner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant