Message30517
"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()
|
|
Date |
User |
Action |
Args |
2007-08-23 14:49:41 | admin | link | issue1594966 messages |
2007-08-23 14:49:41 | admin | create | |
|