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
JavaScript
x
13
13
1
# If extensions (or modules to document with autodoc) are in another directory,
2
# add these directories to sys.path here.
3
import pathlib
4
import sys
5
sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix())
6
7
extensions = [
8
'sphinx.ext.duration',
9
'sphinx.ext.doctest',
10
]
11
12
13
Contents of lumache.py
JavaScript
1
3
1
def get_random_ingredients(kind=None):
2
return ["shells", "gorgonzola", "parsley"]
3
CMD execution
JavaScript
1
3
1
C:docs>make doctest
2
ModuleNotFoundError: No module named 'lumache'
3
Directory Tree:
JavaScript
1
20
20
1
docs/
2
├─build/
3
│ ├─doctest/
4
│ │ └─0 folder(s), 1 file(s)
5
│ ├─doctrees/
6
│ │ └─0 folder(s), 3 file(s)
7
│ └─html/
8
│ └─3 folder(s), 7 file(s)
9
├─make.bat
10
├─Makefile
11
└─source/
12
├─conf.py
13
├─index.rst
14
├─lumache.py
15
├─usage.rst
16
├─_static/
17
│ └─0 folder(s), 0 file(s)
18
└─_templates/
19
└─0 folder(s), 0 file(s)
20
Advertisement
Answer
Move lumache.py
to your project folder (i.e. same folder as where docs/
currently is).