When ever I try to doctest in python, basically whenever I run the code
if __name__ =="__main__":
   import doctest
   doctest.testmod()
I get this response from the interpreter
AttributeError: 'module' object has no attribute 'testmod'
I can run this code just fine, but whenever I run it on my windows machine, it doesn't work.
My machine is running Windows theirs is OS X, but are running python 2.7.5.
Thank you :)
Make sure that you are not trying to save your test file as doctest.py.  The print statement suggested above will show it.  If the file name is doctest.py, then rename it and try again.
AttributeError: 'module' object has no attribute 'testmod'
Clearly stats that the doctest module you're importing do not has the testmod() method.
Possible reasons can be:
doctest modules in the lib. testmod() method) which is getting imported as result of import doctest.Solution: Look for the path of standard doctest module.
if __name__ =="__main__":
   import doctest
   if doctest.__file__  == "/path/to/standard/doctest-module":
       doctest.testmod()
                        It looks like there is a different module called doctest that is being imported instead of the standard one. 
To find out which module is being imported exactly, simply add the following print:
if __name__ =="__main__":
   import doctest
   print doctest.__file__  # add this
   doctest.testmod()
The print should produce something similar to C:\Python27\lib\doctest.pyc, depending on the location and version of Python you're using. Any other output means you are importing the wrong module, and explain why you're getting the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With