Skip to content

Commit 15ddce3

Browse files
Merge pull request #279 from galenseilis/docs-doctests
Docs for doctests file.
2 parents 7103182 + 159fe4b commit 15ddce3

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

doctests.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,58 @@
1+
"""Test hook(s) for Doctests in reStructuredText (.rst) Files."""
2+
13
import doctest
24
import os
35
import unittest
46
import sys
7+
from typing import Any
8+
9+
10+
def load_tests(loader: unittest.TestLoader, tests: unittest.TestSuite, ignorex: Any) -> unittest.TestSuite:
11+
"""
12+
Discover and add all reStructuredText (.rst) doctest files within the current directory tree to the test suite.
13+
14+
Parameters
15+
----------
16+
loader : unittest.TestLoader
17+
The test loader instance used to load the tests.
18+
tests : unittest.TestSuite
19+
The existing test suite to which doctest suites will be added.
20+
ignorex : Any
21+
A placeholder parameter (typically unused) required by the unittest framework.
522
23+
Returns
24+
-------
25+
unittest.TestSuite
26+
The updated test suite including all discovered .rst doctest files.
627
7-
def load_tests(loader, tests, ignorex):
28+
Notes
29+
-----
30+
This function is used by the unittest framework to discover and include additional doctests
31+
in the test suite during test discovery.
32+
33+
Examples
34+
--------
35+
When placed in a test module, unittest will automatically call `load_tests` if it exists.
36+
37+
>>> import unittest
38+
>>> suite = unittest.TestSuite()
39+
>>> loader = unittest.TestLoader()
40+
>>> load_tests(loader, suite, None) # doctest: +ELLIPSIS
41+
<unittest.suite.TestSuite tests=[...]
42+
"""
843
for root, dirs, files in os.walk("."):
944
for f in files:
1045
if f.endswith(".rst"):
1146
tests.addTests(
1247
doctest.DocFileSuite(
13-
os.path.join(root, f), optionflags=doctest.ELLIPSIS
48+
os.path.join(root, f),
49+
optionflags=doctest.ELLIPSIS
1450
)
1551
)
16-
1752
return tests
1853

1954

2055
if __name__ == "__main__":
2156
if sys.version_info >= (3, 6):
2257
unittest.main()
58+

0 commit comments

Comments
 (0)