TEST: Wire docstring doctests into the unittest suite#1076
Open
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
Open
TEST: Wire docstring doctests into the unittest suite#1076christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #473.
test/core/doctest_test.pywhich uses the unittestload_testsprotocol anddoctest.DocTestSuiteto run docstring examples as part of the standard test job. Modules with doctests are listed explicitly inMODULES_WITH_DOCTESTSso the runner does not force-import heavy optional dependencies (LAL, gwpy, samplers) in minimal environments.bilby.core.utils.introspection.infer_args_from_function_except_n_argsfrom a.. code-block:: pythondirective (whichdoctestignores) into a real doctest-format example, so the new runner has a first test to exercise.CONTRIBUTING.md.Rationale: the issue asks for automated discovery of docstring examples and points at the
unittest+doctestintegration, so using theload_testshook keeps discovery automatic and integrates cleanly with the existingpytest testinvocation without requiringpytest --doctest-modules(which would force-import every bilby submodule).Test plan
doctest.DocTestSuiteon a representative module.TestDoctestInfrastructure) confirming thatMODULES_WITH_DOCTESTSis populated, all listed modules import cleanly, and the introspection module reports at least one doctest to theDocTestFinder.test/core/doctest_test.pywithpython -m py_compile.