-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doctests auto addition to unittests suite
- Loading branch information
Showing
1 changed file
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
""" | ||
Add doctests to unittests suite, so you have one nice reports and one test result (exit code). | ||
To add doctests you should import all packages with doctests and list them in doctest_packages | ||
""" | ||
import doctest | ||
from bombard import attr_dict, pretty_ns | ||
from tests import stdout_capture, fake_args | ||
from os.path import dirname, basename, isfile | ||
from glob import glob | ||
from importlib import import_module | ||
import tests | ||
import bombard | ||
|
||
doctests_packages = [bombard, tests] | ||
|
||
PY_EXT = '.py' | ||
|
||
|
||
def load_tests(loader, tests, ignore): | ||
tests.addTest(doctest.DocTestSuite(attr_dict)) | ||
tests.addTest(doctest.DocTestSuite(stdout_capture)) | ||
tests.addTest(doctest.DocTestSuite(fake_args)) | ||
tests.addTest(doctest.DocTestSuite(pretty_ns)) | ||
""" | ||
Unittest hook to add tests to auto-discovered ones | ||
https://docs.python.org/3/library/unittest.html#load-tests-protocol | ||
""" | ||
for package in doctests_packages: | ||
for module_file in glob(dirname(package.__file__) + f'/*{PY_EXT}'): | ||
if isfile(module_file) and not module_file.endswith('__init__.py'): | ||
tests.addTest(doctest.DocTestSuite( | ||
import_module(f'{package.__name__}.{basename(module_file)[:-len(PY_EXT)]}') | ||
)) | ||
return tests |