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:
parent
4100a7f3f5
commit
01d270e39c
5 changed files with 76 additions and 2 deletions
12
noxfile.py
12
noxfile.py
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue