Title: doctest simple usage recipe is misleading
Type: Stage:
Components: Documentation Versions: Python 2.5
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 2007-08-23 20:53 by georg.brandl. 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:

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

    def _test():
        import doctest

    if __name__ == "__main__":

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

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
msg55211 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-23 20:53
Fixed in rev. 57348.
Date User Action Args
2007-08-23 20:53:37georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: fixed
messages: + msg55211
2006-11-12 08:31:52yemircreate