Skip to content

TEST: Wire docstring doctests into the unittest suite#1076

Open
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell:feat/doctest-infra
Open

TEST: Wire docstring doctests into the unittest suite#1076
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell:feat/doctest-infra

Conversation

@christianescamilla15-cell
Copy link
Copy Markdown

Summary

Closes #473.

  • Adds test/core/doctest_test.py which uses the unittest load_tests protocol and doctest.DocTestSuite to run docstring examples as part of the standard test job. Modules with doctests are listed explicitly in MODULES_WITH_DOCTESTS so the runner does not force-import heavy optional dependencies (LAL, gwpy, samplers) in minimal environments.
  • Converts the existing example in bilby.core.utils.introspection.infer_args_from_function_except_n_args from a .. code-block:: python directive (which doctest ignores) into a real doctest-format example, so the new runner has a first test to exercise.
  • Documents the workflow for adding new doctests in CONTRIBUTING.md.

Rationale: the issue asks for automated discovery of docstring examples and points at the unittest + doctest integration, so using the load_tests hook keeps discovery automatic and integrates cleanly with the existing pytest test invocation without requiring pytest --doctest-modules (which would force-import every bilby submodule).

Test plan

  • Verified the new doctest format parses and runs with doctest.DocTestSuite on a representative module.
  • Added sanity-check tests (TestDoctestInfrastructure) confirming that MODULES_WITH_DOCTESTS is populated, all listed modules import cleanly, and the introspection module reports at least one doctest to the DocTestFinder.
  • Compiled test/core/doctest_test.py with python -m py_compile.
  • CI green on bilby-dev CI.

Adds `test/core/doctest_test.py` which uses the unittest `load_tests`
protocol and `doctest.DocTestSuite` to discover and run the `>>>`
examples embedded in bilby docstrings as part of the standard test
job. Modules with doctests are registered explicitly in
`MODULES_WITH_DOCTESTS` so the runner stays safe in minimal environments
where heavy optional dependencies (LAL, gwpy, samplers) are absent.

Converts the existing `infer_args_from_function_except_n_args` example
in `bilby.core.utils.introspection` from a `.. code-block:: python`
directive into a real doctest-format example so that the runner has
something to exercise. Documents the workflow for adding further
doctests in CONTRIBUTING.md.

Closes bilby-dev#473

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add doctest to the bilby test suite

1 participant