Skip to content

Commit 54acdd7

Browse files
committed
Turn on basic doctests for modules and .rst docs
1 parent 193fa24 commit 54acdd7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/practices/unit_testing.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ expected.
2929

3030
It's also worth noting that if you want to write exploratory tests as you develop
3131
your code, but you *do not* want those tests to be included in automated test runs,
32-
feel free to place those tests in a directory outside of the ``./tests`` directory.
32+
feel free to place those tests in a directory outside of the ``./tests`` and
33+
``./src`` directories.
3334

3435
Note that ``pytest`` will recursively search subdirectories inside of ``./tests``
3536
while searching for tests to run.
37+
38+
doctests
39+
-------------------------------------------------------------------------------
40+
41+
In addition to the usual ways of writing unit tests with pytest, our template
42+
supports tests embedded in documentation using pytest's
43+
`doctest <https://doc.pytest.org/en/latest/how-to/doctest.html>`_ component.
44+
Documentation comments in all source files, as well as ``.rst`` files in the ``./docs``
45+
directory can contain doctests in the format outlined
46+
`here <https://doc.pytest.org/en/latest/how-to/doctest.html>`_.

python-project-template/pyproject.toml.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ write_to = "src/{{package_name}}/_version.py"
6363
[tool.pytest.ini_options]
6464
testpaths = [
6565
"tests",
66+
"src",
67+
"docs",
6668
]
69+
addopts = "--doctest-modules --doctest-glob=*.rst"
6770

6871
[tool.black]
6972
line-length = 110

0 commit comments

Comments
 (0)