Skip to content

Commit 94c0e77

Browse files
committed
Set up doctests as unit tests
1 parent 43f0dae commit 94c0e77

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/__init__.py

Whitespace-only changes.

test/test_doctests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import doctest
2+
import unittest
3+
4+
from locate import this_dir
5+
6+
repo_dir = this_dir().parent
7+
8+
9+
def load_tests(loader, tests, ignore):
10+
"""
11+
See https://docs.python.org/3/library/doctest.html#unittest-api
12+
"""
13+
modules = find_modules_with_doctests()
14+
for module in modules:
15+
tests.addTests(doctest.DocTestSuite(module))
16+
return tests
17+
18+
19+
def find_modules_with_doctests():
20+
modules = []
21+
skip_n_parts = len(repo_dir.parts)
22+
for path in repo_dir.joinpath("mkdocstrings_handlers").rglob("*.py"):
23+
if path.name == "__init__.py":
24+
continue
25+
26+
module = ".".join(path.parts[skip_n_parts:])
27+
module = module[:-3]
28+
modules.append(module)
29+
return modules
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main(
34+
failfast=True,
35+
)

0 commit comments

Comments
 (0)