Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:26:20+00:00 2026-06-05T00:26:20+00:00

Python doctests associate simple tests with the source code (in Python they are in

  • 0

Python doctests associate simple tests with the source code (in Python they are in the function documentation). More info and examples here.

Is there anything similar for Clojure?

I am aware of unit tests with clojure.test, but looking for something more closely integrated with the source (typically unit tests are in different files; here I want to have the test “inside” the defn).

Searching around I found this, but it seems very un-lispy (the tests are in actual text, like Python – surely a macro that extends defn would be preferable?).

Or perhaps there is some other way to solve the general problem, which is that I have some tests (generally simple things that demonstrate basic properties of the function) that would be better included with the documentation (I am using marginalia) than in separate unit test files.

update Here’s an example: I have a function that calculates the (manhattan) distance (in pixels) from a rectangle of pixels to the centre of the image. That sounds simple, but is complicated by things like the difference in meaning of “centre” for images with odd or even numbers of pixels on sides, or which part of the block you measure from. So I had to write some tests just to get the code straight. And now I look at the docs and really it would be best if the docs included those tests because they explain better than words what the function does…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:26:21+00:00Added an answer on June 5, 2026 at 12:26 am

    and the test flag in metadata, http://clojure.org/special_forms

    (defn
     ^{:doc "mymax [xs+] gets the maximum value in xs using > "
       :test (fn []
                 (assert (= 42  (mymax 2 42 5 4))))
       :user/comment "this is the best fn ever!"}
      mymax
      ([x] x)
      ([x y] (if (> x y) x y))
      ([x y & more]
       (reduce mymax (mymax x y) more)))
    
    user=> (test #'mymax)
    :ok
    user=> (doc test)
    -------------------------
    clojure.core/test
    ([v])
      test [v] finds fn at key :test in var metadata and calls it,
      presuming failure will throw exception
    nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can put python doctests in the bodies of each function, which I sometimes
I'm interested in learning how to Doctests and Unit tests in a more Agile
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()
I recently faced a problem about combining unit tests and doctests in Python. I
I make extensive use of multiline docstrings in my python source code to include
Today I ran a bunch of doctests using Python 2.6 on a Ubuntu 9.10
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
In my Python development, doctest has really helped both to make writing unit tests
I have a folder with python scripts that contain doc tests that I want
Using the accepted answer (with the doctests) for the Memoized decorator from here: What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.