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 7679293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:50:40+00:00 2026-05-31T17:50:40+00:00

I think I am missing something about the sphinx extension for doctest. The typical

  • 0

I think I am missing something about the sphinx extension for doctest.

The typical example in the documentation is:

.. doctest::

   >>> print 1
   1

Isn’t there a way to let sphinx generate the output (here: 1) automatically?

As far as I understood, it is possible to run:

$ make doctest

which has the effect to test the code snippets, and compare the real output with the expected output. For example, if you have

.. doctest::

   >>> print 1
   3

doctest will warn you that it got 1 while it was expecting 3.

Instead, I would like sphinx to insert the real output alone in my docstring or in my .rst file. For example, if we have something like:

.. doctest::

    >>> print 1
    >>> print [2*x for x in range(3)]

I would like that when we run make doctest with an option, it changes the docstring to:

.. doctest::

   >>> print 1
   1
   >>> print [2*x for x in range(3)]
   [0,2,4]

I’m sure it’s possible, and would be very convenient!

  • 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-05-31T17:50:42+00:00Added an answer on May 31, 2026 at 5:50 pm

    I have to strongly (but kindly) advise against what you’re trying to do.

    What you’re asking is against the “test part” of the doctest module:

    The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.

    These tests have a reasons to be if you write the input and the expected output and let Python check if the expected output match the actual output.

    If you let Python produce the expected output, well.. it will no longer be expected (by the user/author), so the doctests will never fail, hence those tests will be useless.

    Note: If inside a function there’s no logic (if/else, while-loops, appends, etc..) there’s no need to test them. And tests must not reproduce the testing logic, otherwise they’re not testing the function anymore.

    I found this video about test driven development very interesting, maybe it could be of interest to you if you want to know more about this argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I am missing something about property attributes. First, I can't understand the
OK I have looked and looked and I think I am missing something about
I think I'm missing something obvious about sitemaps. I'm trying to use a repeater
I think i'm missing something fundamental about how Hibernate works, specifically with lazy loading.
I think I'm missing something very obvious and its making my brain hurt. class
After messing about with F# there are some really nice features that I think
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
Maybe I'm totally missing something about even handling in jQuery, but here's my problem.
Am I thinking about this all wrong , or am I missing something that's
I think I'm missing something obvious.... I've been reading code in a new project

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.