I'm having trouble using doctest with relative imports. The simple solution is just to get rid of the relative imports. Are there any others?
Say I have a package called example containing 2 files:
example/__init__.py
"""
This package is entirely useless.
>>> arnold = Aardvark()
>>> arnold.talk()
I am an aardvark.
"""
from .A import Aardvark
if __name__ == "__main__":
import doctest
doctest.testmod()
example/A.py
class Aardvark(object):
def talk(self):
print("I am an aardvark.")
If I now attempt
python example/__init__.py
then I get the error
Traceback (most recent call last):
File "example/__init__.py", line 8, in <module>
from .A import Aardvark
ValueError: Attempted relative import in non-package
numpy
these are very common. – Euratom