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.

classification
Title: doctest simple usage recipe is misleading
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: georg.brandl, tim.peters, yemir
Priority: low Keywords:

Created on 2006-11-12 08:31 by yemir, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30517 - (view) Author: Ken Rimey (yemir) Date: 2006-11-12 08:31
"23.2.1 Simple Usage: Checking Examples in Docstrings" sets up a trap 
for the unsuspecting developer:

    http://docs.python.org/lib/doctest-simple-testmod.html

That page recommends adding the following code to the end of a 
module using doctest:

    def _test():
        import doctest
        doctest.testmod()

    if __name__ == "__main__":
        _test()

The problem is that a reasonable person will figure that _test() has 
been defined for convenience in executing the tests from other Python 
code as follows:

    import M
    M._test()

However, that executes the doctests found in __main__, not M!

I think the recommended recipe should instead be as follows:

    if __name__ == "__main__":
        import doctest
        doctest.testmod()
msg55211 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-23 20:53
Fixed in rev. 57348.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44224
2007-08-23 20:53:37georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg55211
2006-11-12 08:31:52yemircreate