I have a problem trying to run doctest
from the Sphinx Tutorial. I have the directory tree below but I cannot run a doctest
for lumache.py
. How would be able to make it so that lumache.py
is importable with the pathlib
function in conf.py
which is sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix())
.The code I am trying to execute is of the same one from the tutorial (hyperlink mentioned in the first sentence).
conf.py Contents
# If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. import pathlib import sys sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix()) extensions = [ 'sphinx.ext.duration', 'sphinx.ext.doctest', ] ...
Contents of lumache.py
def get_random_ingredients(kind=None): return ["shells", "gorgonzola", "parsley"]
CMD execution
C:docs>make doctest ModuleNotFoundError: No module named 'lumache'
Directory Tree:
docs/ ├─build/ │ ├─doctest/ │ │ └─0 folder(s), 1 file(s) │ ├─doctrees/ │ │ └─0 folder(s), 3 file(s) │ └─html/ │ └─3 folder(s), 7 file(s) ├─make.bat ├─Makefile └─source/ ├─conf.py ├─index.rst ├─lumache.py ├─usage.rst ├─_static/ │ └─0 folder(s), 0 file(s) └─_templates/ └─0 folder(s), 0 file(s)
Advertisement
Answer
Move lumache.py
to your project folder (i.e. same folder as where docs/
currently is).