Skip to content

Docs for doctests file. #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions doctests.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
"""Test hook(s) for Doctests in reStructuredText (.rst) Files."""

import doctest
import os
import unittest
import sys
from typing import Any


def load_tests(loader: unittest.TestLoader, tests: unittest.TestSuite, ignorex: Any) -> unittest.TestSuite:
"""
Discover and add all reStructuredText (.rst) doctest files within the current directory tree to the test suite.

Parameters
----------
loader : unittest.TestLoader
The test loader instance used to load the tests.
tests : unittest.TestSuite
The existing test suite to which doctest suites will be added.
ignorex : Any
A placeholder parameter (typically unused) required by the unittest framework.

Returns
-------
unittest.TestSuite
The updated test suite including all discovered .rst doctest files.

def load_tests(loader, tests, ignorex):
Notes
-----
This function is used by the unittest framework to discover and include additional doctests
in the test suite during test discovery.

Examples
--------
When placed in a test module, unittest will automatically call `load_tests` if it exists.

>>> import unittest
>>> suite = unittest.TestSuite()
>>> loader = unittest.TestLoader()
>>> load_tests(loader, suite, None) # doctest: +ELLIPSIS
<unittest.suite.TestSuite tests=[...]
"""
for root, dirs, files in os.walk("."):
for f in files:
if f.endswith(".rst"):
tests.addTests(
doctest.DocFileSuite(
os.path.join(root, f), optionflags=doctest.ELLIPSIS
os.path.join(root, f),
optionflags=doctest.ELLIPSIS
)
)

return tests


if __name__ == "__main__":
if sys.version_info >= (3, 6):
unittest.main()

Loading