In the doctests of my module I would like to reference my module with the full namespace, for example:
hp.myfunc(1)
And I would like to avoid cluttering the doctests by writing:
import healpy as hp
in each of the doctests.
if I run doctest.testmod, I know I can use the globs keyword to provide this, while if I run nose, I can use the setup function.
Is there another standard way that could work with both?
How are you running the doctests (without nose, that is)? If you are cd’d into the package directory when you attempt to run them, you will run into problems (if you are doing a full import, that is).
I was able to get a simple doctest (with fully-qualified imports) running with both nosetests and the builtin doctest runner. Here’s my setup:
Project structure:
Here are the contents of my ‘mod.py’ file:
from the ‘.’ directory (project root), I can now run tests:
And now the nosetests:
If I try to run the doctest from within the ‘mypackage’ directory, I get an error (which is, I suspect, what’s happening in your case).
Finally, I don’t think this should make a difference, but I’m running Python 2.7.2