Skip to content

Commit

Permalink
doctests auto addition to unittests suite
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Apr 20, 2019
1 parent 3cca408 commit 8a73ba1
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions tests/test_doctests.py
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

0 comments on commit 8a73ba1

Please sign in to comment.