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

23
tests/test_docstrings.py Normal file
View file

@ -0,0 +1,23 @@
"""Integrate `xdoctest` into the test suite.
Ensure all code snippets in docstrings are valid and functioning code.
Important: All modules with docstrings containing code snippets
must be put on the parameter list below by hand!
"""
import pytest
import xdoctest
@pytest.mark.parametrize(
"module",
[
"lalib",
],
)
def test_docstrings(module):
"""Test code snippets within the package with `xdoctest`."""
result = xdoctest.doctest_module(module, "all")
assert result["n_failed"] == 0