Commit 3e2ee32d by Chris Jerdonek

Replaced the TestHarness class with a run_tests() function.

parent 3e20e423
...@@ -7,12 +7,11 @@ This module provides a command to test pystache (unit tests, doctests, etc). ...@@ -7,12 +7,11 @@ This module provides a command to test pystache (unit tests, doctests, etc).
import sys import sys
from pystache.tests.main import TestHarness from pystache.tests.main import run_tests
def main(sys_argv=sys.argv): def main(sys_argv=sys.argv):
harness = TestHarness() run_tests(sys_argv=sys_argv)
harness.run_tests(sys_argv=sys_argv)
if __name__=='__main__': if __name__=='__main__':
......
# coding: utf-8 # coding: utf-8
""" """
Allows all tests to be run. Exposes a run_tests() function that runs all tests in the project.
This module is for our test console script. This module is for our test console script.
...@@ -34,6 +34,30 @@ UNITTEST_FILE_PREFIX = "test_" ...@@ -34,6 +34,30 @@ UNITTEST_FILE_PREFIX = "test_"
# TestCase or TestSuite instances (e.g. doctests and spec tests), and then # TestCase or TestSuite instances (e.g. doctests and spec tests), and then
# call the base class's runTests(). # call the base class's runTests().
def run_tests(sys_argv):
"""
Run all tests in the project.
Arguments:
sys_argv: a reference to sys.argv.
"""
if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"):
# Then no explicit module or test names were provided, so
# auto-detect all unit tests.
module_names = _discover_test_modules(PACKAGE_DIR)
sys_argv.extend(module_names)
# We pass None for the module because we do not want the unittest
# module to resolve module names relative to a given module.
# (This would require importing all of the unittest modules from
# this module.) See the loadTestsFromName() method of the
# unittest.TestLoader class for more details on this parameter.
_PystacheTestProgram(argv=sys_argv, module=None)
# No need to return since unitttest.main() exits.
def _find_unittest_files(package_dir): def _find_unittest_files(package_dir):
""" """
Return a list of paths to all unit-test files in the given package directory. Return a list of paths to all unit-test files in the given package directory.
...@@ -125,34 +149,3 @@ class _PystacheTestProgram(TestProgram): ...@@ -125,34 +149,3 @@ class _PystacheTestProgram(TestProgram):
self.test.addTests(doctest_suites) self.test.addTests(doctest_suites)
TestProgram.runTests(self) TestProgram.runTests(self)
class TestHarness(object):
"""
Discovers and runs unit tests.
"""
def run_tests(self, sys_argv):
"""
Run all unit tests inside the given package.
Arguments:
sys_argv: a reference to sys.argv.
"""
if len(sys_argv) <= 1 or sys_argv[-1].startswith("-"):
# Then no explicit module or test names were provided, so
# auto-detect all unit tests.
module_names = _discover_test_modules(PACKAGE_DIR)
sys_argv.extend(module_names)
# We pass None for the module because we do not want the unittest
# module to resolve module names relative to a given module.
# (This would require importing all of the unittest modules from
# this module.) See the loadTestsFromName() method of the
# unittest.TestLoader class for more details on this parameter.
_PystacheTestProgram(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