-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_doctests.py
37 lines (29 loc) · 956 Bytes
/
test_doctests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import doctest
import unittest
from pathlib import Path
from typing import Any, List
from unittest import BaseTestSuite
repo_dir = Path(__file__).resolve().parent.parent
# noinspection PyUnusedLocal
def load_tests(loader: Any, tests: BaseTestSuite, ignore: Any) -> BaseTestSuite:
"""
See https://docs.python.org/3/library/doctest.html#unittest-api
"""
modules = find_modules_with_doctests()
for module in modules:
tests.addTests(doctest.DocTestSuite(module))
return tests
def find_modules_with_doctests() -> List[str]:
modules = []
skip_n_parts = len(repo_dir.parts)
for path in repo_dir.joinpath("mkdocstrings_handlers").rglob("*.py"):
if path.name == "__init__.py":
continue
module = ".".join(path.parts[skip_n_parts:])
module = module[:-3]
modules.append(module)
return modules
if __name__ == "__main__":
unittest.main(
failfast=True,
)