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
23
tests/test_docstrings.py
Normal file
23
tests/test_docstrings.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue