Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add before and after options #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

deadghost
Copy link

I wanted global fixtures that will setup before testing and teardown after testing. I generalized it as -b[efore] and -a[fter]. They take Symbol indicating the fully qualified name of a specific function to run before/after tests. I'm open to option naming and code review. I have (after args) in two places because of (System/exit) and it feels kind of gross.

test-runner is meant to work with clojure CLI tools in 1.9.0
anyways.
@puredanger
Copy link
Contributor

I know this is super old, but curious what you needed to do in before/after...

@deadghost
Copy link
Author

Yeah it's been a long time so I don't remember all the details. I believe it was to set up a test db only once for tests across multiple namespaces. The tests themselves did speculative transactions for testing. Then after all the tests finished, the db would be torn down.

use-fixtures can have setup/teardown granularity on a per function or per namespace basis with :each and :once but not for the entire test run across all namespaces. Setup/teardown can be resource intensive and I'd want to run them as few times as possible.

@darkleaf
Copy link

It is not required to modify test-runner for this.
You could write own wrapper function:

;; src/my/app/wrapper.clj
(ns my.app.wrapper)

(defn wrap [{:keys [f] :as args}]
  (let [f (requiring-resolve f)]
    (prn "~~~before~~~")
    (f args)))

;; deps.edn
{,,,
  :test  {:extra-paths ["test"]
          :extra-deps  {io.github.cognitect-labs/test-runner
                        {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
          :exec-fn     my.app.wrapper/wrap ;; use wrapper instead of `cognitect.test-runner.api/test`
          :exec-args   {:f cognitect.test-runner.api/test}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants