This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: doctest example exit status
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Brainix, berker.peksag, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2016-11-17 01:19 by Brainix, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg281015 - (view) Author: Rajiv Bakulesh Shah (Brainix) Date: 2016-11-17 01:19
It might be nice if the doctest example set the appropriate exit status.  Apologies if this is beyond the scope of the example, but I thought it might be good practice.

Here is the file:

Here is the example as written:
if __name__ == "__main__":
    import doctest

Here is my proposal:
if __name__ == '__main__':
    import doctest
    import sys
    results = doctest.testmod()

I'm happy to fork the repo and submit a PR, if that makes things easier.  I'm not familiar with the protocol here.  Thanks for the great work!
msg281571 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-11-23 16:37
Hi Rajiv, thanks for the report, but this is already possible by default. I will use the factorial example from to demonstrate it:

    $ python -m doctest
    $ echo $?

Now change the following line

    >>> [factorial(n) for n in range(6)]


    >>> [factorial(n) for n in range(5)]

and run the script again:

    $ python -m doctest
    ***Test Failed*** 1 failures.
    $ echo $?
msg281574 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-11-23 18:06
Rajiv is suggesting an improvement to the documentation.  I think it is a reasonable thought, but probably not a good idea on closer examination.  The example introduces the basic doctest concepts, and goes on to say that this is not the mostly likely way to make use of doctest (and indeed it is not common).  So complicating the example and the explanation would be counterproductive to the intent of the text, in my opinion.
Date User Action Args
2022-04-11 14:58:39adminsetgithub: 72908
2016-11-23 18:06:02r.david.murraysetnosy: + r.david.murray
messages: + msg281574
2016-11-23 16:37:11berker.peksagsetstatus: open -> closed

type: enhancement

nosy: + berker.peksag
messages: + msg281571
resolution: not a bug
stage: resolved
2016-11-17 01:19:40Brainixcreate