cognitect-labs/test-runner

Tests are run in `user` namespace

raystubbs opened this issue · 4 comments

Using clj -X:test seems to run the tests in the user namespace, which breaks tests that rely on *ns*. Here's a repro.

(ns example.core-test
  (:require
    [clojure.test :refer [deftest is]]))

(deftest example-test
  (is (= (str *ns*) "example.core-test")))

Result:

FAIL in (example-test) (core_test.cljc:24)
expected: (= (str *ns*) "example.core-test")
  actual: (not (= "user" "example.core-test"))

Do you have an example closer to what actually fails due to this?

Yeah, this test fails since the defclass macro bases class names on the current ns.

I don't think there is any good reason to have this expectation. clojure.test tests can be run from any namespace and often are run from namespaces other than the place where they are defined.

If you want to enforce this constraint, you can do so via a :once fixture:

(defn ns-fixture
  [f]
  (in-ns 'example.core-test)
  (f))

(use-fixtures :once ns-fixture)

Hmm, okay. Seems odd that you can't depend on the namespace; but makes some sense if that's the convention.