Add doctests to the test suite

- use xdoctest to validate code snippets in docstrings
- make xdoctest part of the nox session "test" via
  the new `test_docstrings()` test case
- add nox session "test-docstrings" for convenience;
  also, `xdoctest.doctest_module()` does not discover
  docstrings that are imported at the root of the package
  => each new module with docstrings must be added to
     `test_docstrings()` by hand, which is likely forgotten
  => the nox session "test-docstrings" should run on CI
This commit is contained in:
Alexander Hess 2024-09-10 01:57:02 +02:00
commit 01d270e39c
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
5 changed files with 76 additions and 2 deletions

View file

@ -76,6 +76,7 @@ nox.options.reuse_venv = "no"
nox.options.sessions = ( # run by default when invoking `nox` on the CLI
"format",
"lint",
"test-docstrings",
f"test-{MAIN_PYTHON}",
)
nox.options.stop_on_first_error = True
@ -156,6 +157,7 @@ def test(session: nox.Session) -> None:
"pytest",
"pytest-cov",
"semver",
"xdoctest",
)
args = session.posargs or (
@ -167,6 +169,16 @@ def test(session: nox.Session) -> None:
session.run("pytest", *args)
@nox_session(name="test-docstrings", python=MAIN_PYTHON)
def test_docstrings(session: nox.Session) -> None:
"""Test docstrings with `xdoctest`."""
start(session)
install_pinned(session, "xdoctest[colors]")
session.run("xdoctest", "--version")
session.run("xdoctest", "src/lalib")
def start(session: nox.Session) -> None:
"""Show generic info about a session."""
if session.posargs: