From 242048ad698cde3bd7471ac5c432b1c56f6b9bba Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Mon, 12 Sep 2011 13:40:19 -0500 Subject: Add toggle to run tests in-process, w/ realtime progress feedback Change-Id: I4b4d0c24d2718f2902b71d98e9bde3dcefb19c70 --- keystone/test/__init__.py | 20 ++++++++++++++------ run_tests.sh | 4 ++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/keystone/test/__init__.py b/keystone/test/__init__.py index 2aef27c4..9b8c924f 100644 --- a/keystone/test/__init__.py +++ b/keystone/test/__init__.py @@ -91,11 +91,19 @@ class KeystoneTest(object): # discover and run tests print "Running tests..." - loader = unittest.TestLoader() - suite = loader.discover(TEST_DIR, top_level_dir=BASE_DIR) - result = unittest.TextTestRunner(verbosity=1).run(suite) - if not result.wasSuccessful(): - raise RuntimeError("%s unresolved issues." % - (len(result.errors) + len(result.failures),)) + if '--with-progress' in sys.argv: + loader = unittest.TestLoader() + suite = loader.discover(TEST_DIR, top_level_dir=BASE_DIR) + result = unittest.TextTestRunner(verbosity=1).run(suite) + if not result.wasSuccessful(): + raise RuntimeError("%s unresolved issues." % + (len(result.errors) + len(result.failures),)) + elif '--with-coverage' in sys.argv: + print "running coverage" + execute('coverage run %s discover -t %s -s %s' % + ('/usr/bin/unit2', BASE_DIR, TEST_DIR)) + else: + execute('unit2 discover -f -t %s -s %s' % + (BASE_DIR, TEST_DIR)) finally: self.tearDown() diff --git a/run_tests.sh b/run_tests.sh index 60b321ae..aee3f055 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -8,6 +8,10 @@ function usage { echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." echo " --unittests-only Run unit tests only, exclude functional tests." + echo " --with-coverage Runs tests with python code coverage (useful for jenkins)" + echo " Note: cannot be used in combination --with-progress" + echo " --with-progress Runs tests with progress (useful for developers)" + echo " Note: cannot be used in combination --with-coverage" echo " -p, --pep8 Just run pep8" echo " -l, --pylint Just run pylint" echo " -h, --help Print this usage message" -- cgit