From 4221bf9ec0651cffd66aca9f6edd28447f182d7f Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 6 Jun 2014 13:02:56 -0400 Subject: [PATCH] Set verbosity on paver test tasks --- pavelib/tests.py | 29 +++++++++++++++++++++---- pavelib/utils/test/suites/i18n_suite.py | 4 +++- pavelib/utils/test/suites/nose_suite.py | 9 +++++--- pavelib/utils/test/suites/suite.py | 10 +++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/pavelib/tests.py b/pavelib/tests.py index 150e2c8a2c..4ec4f64536 100644 --- a/pavelib/tests.py +++ b/pavelib/tests.py @@ -6,6 +6,7 @@ import sys from paver.easy import sh, task, cmdopts, needs from pavelib.utils.test import suites from pavelib.utils.envs import Env +from optparse import make_option try: from pygments.console import colorize @@ -25,7 +26,10 @@ __test__ = False # do not collect ("test_id=", "t", "Test id"), ("failed", "f", "Run only failed tests"), ("fail_fast", "x", "Run only failed tests"), - ("fasttest", "a", "Run without collectstatic") + ("fasttest", "a", "Run without collectstatic"), + make_option("--verbose", action="store_const", const=2, dest="verbosity"), + make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"), + make_option("-v", "--verbosity", action="count", dest="verbosity", default=1), ]) def test_system(options): """ @@ -38,6 +42,7 @@ def test_system(options): 'failed_only': getattr(options, 'failed', None), 'fail_fast': getattr(options, 'fail_fast', None), 'fasttest': getattr(options, 'fasttest', None), + 'verbosity': getattr(options, 'verbosity', 1), } if test_id: @@ -66,6 +71,9 @@ def test_system(options): ("test_id=", "t", "Test id"), ("failed", "f", "Run only failed tests"), ("fail_fast", "x", "Run only failed tests"), + make_option("--verbose", action="store_const", const=2, dest="verbosity"), + make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"), + make_option("-v", "--verbosity", action="count", dest="verbosity", default=1), ]) def test_lib(options): """ @@ -77,6 +85,7 @@ def test_lib(options): opts = { 'failed_only': getattr(options, 'failed', None), 'fail_fast': getattr(options, 'fail_fast', None), + 'verbosity': getattr(options, 'verbosity', 1), } if test_id: @@ -98,6 +107,9 @@ def test_lib(options): @cmdopts([ ("failed", "f", "Run only failed tests"), ("fail_fast", "x", "Run only failed tests"), + make_option("--verbose", action="store_const", const=2, dest="verbosity"), + make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"), + make_option("-v", "--verbosity", action="count", dest="verbosity", default=1), ]) def test_python(options): """ @@ -106,6 +118,7 @@ def test_python(options): opts = { 'failed_only': getattr(options, 'failed', None), 'fail_fast': getattr(options, 'fail_fast', None), + 'verbosity': getattr(options, 'verbosity', 1), } python_suite = suites.PythonTestSuite('Python Tests', **opts) @@ -130,13 +143,21 @@ def test_i18n(): 'pavelib.prereqs.install_prereqs', 'pavelib.utils.test.utils.clean_reports_dir', ) -def test(): +@cmdopts([ + make_option("--verbose", action="store_const", const=2, dest="verbosity"), + make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"), + make_option("-v", "--verbosity", action="count", dest="verbosity", default=1), +]) +def test(options): """ Run all tests """ + opts = { + 'verbosity': getattr(options, 'verbosity', 1) + } # Subsuites to be added to the main suite - python_suite = suites.PythonTestSuite('Python Tests') - i18n_suite = suites.I18nTestSuite('i18n') + python_suite = suites.PythonTestSuite('Python Tests', **opts) + i18n_suite = suites.I18nTestSuite('i18n', **opts) js_suite = suites.JsTestSuite('JS Tests', mode='run', with_coverage=True) # Main suite to be run diff --git a/pavelib/utils/test/suites/i18n_suite.py b/pavelib/utils/test/suites/i18n_suite.py index 9c079aad9b..5de6f91bc8 100644 --- a/pavelib/utils/test/suites/i18n_suite.py +++ b/pavelib/utils/test/suites/i18n_suite.py @@ -30,10 +30,12 @@ class I18nTestSuite(TestSuite): cmd = ( "{pythonpath_prefix} nosetests {repo_root}/i18n/tests " - "--with-xunit --xunit-file={xunit_report}".format( + "--with-xunit --xunit-file={xunit_report} " + "--verbosity={verbosity}.format( pythonpath_prefix=pythonpath_prefix, repo_root=Env.REPO_ROOT, xunit_report=self.xunit_report, + verbosity=self.verbosity, ) ) diff --git a/pavelib/utils/test/suites/nose_suite.py b/pavelib/utils/test/suites/nose_suite.py index 4ea37497db..9460793d8d 100644 --- a/pavelib/utils/test/suites/nose_suite.py +++ b/pavelib/utils/test/suites/nose_suite.py @@ -110,9 +110,10 @@ class SystemTestSuite(NoseTestSuite): @property def cmd(self): cmd = ( - './manage.py {system} test {test_id} {test_opts} ' - '--traceback --settings=test'.format( + './manage.py {system} test --verbosity={verbosity} ' + '{test_id} {test_opts} --traceback --settings=test'.format( system=self.root, + verbosity=self.verbosity, test_id=self.test_id, test_opts=self.test_options_flags, ) @@ -158,11 +159,13 @@ class LibTestSuite(NoseTestSuite): def cmd(self): cmd = ( "nosetests --id-file={test_ids} {test_id} {test_opts} " - "--with-xunit --xunit-file={xunit_report}".format( + "--with-xunit --xunit-file={xunit_report} " + "--verbosity={verbosity}".format( test_ids=self.test_ids, test_id=self.test_id, test_opts=self.test_options_flags, xunit_report=self.xunit_report, + verbosity=self.verbosity, ) ) diff --git a/pavelib/utils/test/suites/suite.py b/pavelib/utils/test/suites/suite.py index 96409cb76f..0556e5eb76 100644 --- a/pavelib/utils/test/suites/suite.py +++ b/pavelib/utils/test/suites/suite.py @@ -21,6 +21,16 @@ class TestSuite(object): self.root = args[0] self.subsuites = kwargs.get('subsuites', []) self.failed_suites = [] + self.verbosity = kwargs.get('verbosity', 1) + + @property + def verbose(self): + """ + Boolean version of `self.verbosity`. If `self.verbosity` is greater than + 1, `self.verbose` is True. Note that the default value for + `self.verbosity` is 1, so the default value for `self.verbose` is False. + """ + return self.verbosity > 1 def __enter__(self): """