Skip to content

Commit

Permalink
doctests auto addition to unittests suite 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Apr 20, 2019
1 parent 8a73ba1 commit d98e166
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"""
Add doctests to unittests suite, so you have one nice reports and one test result (exit code).
doctests from all modules of packages listed in PACKAGES
will be added to unit tests suite.
To add doctests you should import all packages with doctests and list them in doctest_packages
So you will have one nice test report and one test result/exit code in CI.
You should import below all your packages with doctests and list them in PACKAGES.
"""
import doctest
from os.path import dirname, basename, isfile
from glob import glob
from importlib import import_module

import tests
import bombard

doctests_packages = [bombard, tests]
PACKAGES = [bombard, tests]

PY_EXT = '.py'

Expand All @@ -20,7 +23,7 @@ def load_tests(loader, tests, ignore):
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 package in 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(
Expand Down

0 comments on commit d98e166

Please sign in to comment.