Search code examples
testingclojureleiningen

Exclude tests with a specific selector in lein test


I have a suite of tests in my leiningen-based Clojure project.

I want to run most of them frequently, but I want to exclude those with the :integration selector because they are slow and flaky.

If I understand correctly there's a built-in :only selector in leiningen which will run only the matching tests:

lein test :only :integration

I want a :not selector which does the opposite (runs all except :integration).

lein test :not :integration

Is there a way to build this with the facilities provided by lein test?

I know I can write a fn like (complement :integration) and put it in the :test-selectors map in my project.clj but it'll be hard-coded to ignore :integration -- what I really want is a general :not that I can parameterize with a keyword, so I can ignore my :slow or :flaky tests in other circumstances.


Solution

  • I don't think you can do it with keywords, since they are picked up by Leiningen as arguments. But you can create a custom test selector that you pass a string:

    :test-selectors {:not (fn [m s] (not (contains? m (keyword s))))}
    

    That you can call with lein test :not integration or lein test :not flaky.