diff --git a/docs/practices/unit_testing.rst b/docs/practices/unit_testing.rst index cc95c75..be13496 100644 --- a/docs/practices/unit_testing.rst +++ b/docs/practices/unit_testing.rst @@ -29,7 +29,18 @@ expected. It's also worth noting that if you want to write exploratory tests as you develop your code, but you *do not* want those tests to be included in automated test runs, -feel free to place those tests in a directory outside of the ``./tests`` directory. +feel free to place those tests in a directory outside of the ``./tests`` and +``./src`` directories. Note that ``pytest`` will recursively search subdirectories inside of ``./tests`` while searching for tests to run. + +doctests +------------------------------------------------------------------------------- + +In addition to the usual ways of writing unit tests with pytest, our template +supports tests embedded in documentation using pytest's +`doctest `_ component. +Documentation comments in all source files, as well as ``.rst`` files in the ``./docs`` +directory can contain doctests in the format outlined +`here `_. \ No newline at end of file diff --git a/python-project-template/pyproject.toml.jinja b/python-project-template/pyproject.toml.jinja index 8c4b23b..7db20a8 100644 --- a/python-project-template/pyproject.toml.jinja +++ b/python-project-template/pyproject.toml.jinja @@ -63,7 +63,10 @@ write_to = "src/{{package_name}}/_version.py" [tool.pytest.ini_options] testpaths = [ "tests", + "src", + "docs", ] +addopts = "--doctest-modules --doctest-glob=*.rst" [tool.black] line-length = 110 diff --git a/python-project-template/src/{{package_name}}/{% if create_example_module %}example_module.py{% endif %} b/python-project-template/src/{{package_name}}/{% if create_example_module %}example_module.py{% endif %} index f76e837..81197e7 100644 --- a/python-project-template/src/{{package_name}}/{% if create_example_module %}example_module.py{% endif %} +++ b/python-project-template/src/{{package_name}}/{% if create_example_module %}example_module.py{% endif %} @@ -4,6 +4,12 @@ def greetings() -> str: """A friendly greeting for a future friend. + Example: + >>> greetings() + 'Hello from LINCC-Frameworks!' + + Note: this example becomes a unit test via doctests + Returns ------- str @@ -15,6 +21,12 @@ def greetings() -> str: def meaning() -> int: """The meaning of life, the universe, and everything. + Example: + >>> meaning() + 42 + + Note: this example becomes a unit test via doctests + Returns ------- int