Commit 8aa242e9 by Chris Jerdonek

Finished refactoring pystache/tests/main.py prior to add doctest support, etc.

parent d9e84960
...@@ -94,6 +94,22 @@ def _get_test_module_names(package_dir): ...@@ -94,6 +94,22 @@ def _get_test_module_names(package_dir):
return modules return modules
def _discover_test_modules(package):
"""
Discover and return a sorted list of the names of unit-test modules.
"""
package_dir = os.path.dirname(package.__file__)
modules = _get_test_module_names(package_dir)
modules.sort()
# This is a sanity check to ensure that the unit-test discovery
# methods are working.
if len(modules) < 1:
raise Exception("No unit-test modules found.")
return modules
class _PystacheTestProgram(TestProgram): class _PystacheTestProgram(TestProgram):
pass pass
...@@ -118,23 +134,11 @@ class Tester(object): ...@@ -118,23 +134,11 @@ class Tester(object):
sys_argv: a reference to sys.argv. sys_argv: a reference to sys.argv.
""" """
if len(sys_argv) > 1 and not sys_argv[-1].startswith("-"): if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"):
# Then explicit modules or test names were provided, which # Then no explicit module or test names were provided, so
# the unittest module is equipped to handle. # auto-detect all unit tests.
unittest.main(argv=sys_argv, module=None) module_names = _discover_test_modules(package)
# No need to return since unitttest.main() exits. sys_argv.extend(module_names)
# Otherwise, auto-detect all unit tests.
package_dir = os.path.dirname(package.__file__)
modules = _get_test_module_names(package_dir)
modules.sort()
# This is a sanity check to ensure that the unit-test discovery
# methods are working.
if len(modules) < 1:
raise Exception("No unit-test modules found.")
sys_argv.extend(modules)
# We pass None for the module because we do not want the unittest # We pass None for the module because we do not want the unittest
# module to resolve module names relative to a given module. # module to resolve module names relative to a given module.
...@@ -142,3 +146,4 @@ class Tester(object): ...@@ -142,3 +146,4 @@ class Tester(object):
# this module.) See the loadTestsFromName() method of the # this module.) See the loadTestsFromName() method of the
# unittest.TestLoader class for more details on this parameter. # unittest.TestLoader class for more details on this parameter.
unittest.main(argv=sys_argv, module=None) unittest.main(argv=sys_argv, module=None)
# No need to return since unitttest.main() exits.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment