Question
I try to use doctest from example from http://docs.python.org/library/doctest.html
But when I run
python example.py -v
I get this
Traceback (most recent call last):
File "example.py", line 61, in <module>
doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'
But I can import doctest in python interactive shell and enable to use doctest.testmod() as well. I searched in google and didn't find the solution.
Python version is 2.5.1 on Max OSX
Solution
Clearly the doctest
module object you have at hand at that point is NOT the normal, unadulterated one you get from an import doctest
from the standard library. Printing doctest.__file__
(and sys.stdout.flush()
ing after that, just to make sure you do get to see the results;-) before the line-61 exception will let you know WHERE that stray doctest
module is coming from.
If you show us example.py
as well as that output we can probably point out what exactly you may be doing wrong, if it doesn't already become obvious to you.
OTHER TIPS
Try inserting a
print doctest, dir(doctest)
before line 61. This will tell you the location of the doctest module, and what attributes it has. You can do this to make sure that there's nothing wrong with your doctest module.