Skip to content

Commit

Permalink
Added --quiet-nice-dots to hide the summary (i.e. only print errors o…
Browse files Browse the repository at this point in the history
…nce)
  • Loading branch information
kumar303 committed Dec 18, 2010
1 parent 55746ba commit 3ab46ec
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
16 changes: 11 additions & 5 deletions README.rst
Expand Up @@ -55,12 +55,18 @@ Example

FAILED (failures=1)

Caveats
=======
Additional Options
==================

This will probably only work in Python 2.6! That might be fixable by creating different result instances per version.
**--quiet-nice-dots**
By default, errors are printed when the occur and also
in the summary. Set this to hide them in the summary.

Known Issues
============
Caveats
=======

- This will probably only work in Python 2.6! That might be fixable by
creating different result instances per version.
- SkipTest is not fully supported. It kinda works.
- If any other plugin needs to patch the unittest result then it will
conflict with Nice Dots.
28 changes: 18 additions & 10 deletions nosenicedots/plugin.py
Expand Up @@ -24,28 +24,25 @@ class NiceDots(Plugin):
def options(self, parser, env=os.environ):
super(NiceDots, self).options(parser, env=env)
self.parser = parser
self.parser.add_option('--quiet-nice-dots',
action='store_true', dest='quiet',
help=('By default, errors are printed when the occur and also '
'in the summary. Set this to hide them in the summary.'))

def configure(self, options, conf):
super(NiceDots, self).configure(options, conf)
if not self.enabled:
return
self.options = options
self.cmd_options = options

def prepareTestResult(self, result):
# TODO(Kumar) this will break when unittest changes.
# Current code is from 2.6

# Don't repeat failures at the bottom? Hmm.

# def printErrors():
# # We already printed errors:
# self.stream.writeln("")
#
# result.printErrors = printErrors

nice_result = NiceDotsResult(self.runner.stream,
self.runner.descriptions,
self.runner.verbosity)
self.runner.verbosity,
hide_summary=self.cmd_options.quiet)

# Monkey patch unittest result with a custom result.
# This is because Nose cannot completely replace the
Expand All @@ -67,6 +64,10 @@ def prepareTestRunner(self, runner):

class NiceDotsResult(_TextTestResult):

def __init__(self, stream, descriptions, verbosity, hide_summary=False):
super(NiceDotsResult, self).__init__(stream, descriptions, verbosity)
self.hide_summary = hide_summary

def getDescription(self, test):
return nice_test_address(test)

Expand All @@ -79,6 +80,13 @@ def printError(self, flavour, err, test):
self.stream.writeln(self.separator2)
self.stream.writeln("%s" % err)

def printErrors(self):
if self.hide_summary:
# Note that errors were already printed as soon as they occurred.
self.stream.writeln("")
else:
super(NiceDotsResult, self).printErrors()

def addError(self, test, err):
exc, val, tb = err
if not issubclass(exc, SkipTest):
Expand Down
18 changes: 17 additions & 1 deletion nosenicedots/tests/test_functional.py
Expand Up @@ -23,9 +23,10 @@ class NiceDotsTest(PluginTester):
def makeSuite(self):
pass


class TestDefaults(NiceDotsTest, unittest.TestCase):

def test_foo(self):
def test_suite(self):
print '>' * 80
print self.output
print '>' * 80
Expand Down Expand Up @@ -55,3 +56,18 @@ def test_foo(self):
'FAIL: nosenicedots/tests/example-suite/test_stuff/'
'test_classes.py:TestClass.test_failing'),
2)


class TestQuietNiceDots(NiceDotsTest, unittest.TestCase):
args = ['--quiet-nice-dots']

def test_suite(self):
print '>' * 80
print self.output
print '>' * 80

# Summary should be hidden:
eq_(str_count(self.output,
'FAIL: nosenicedots/tests/example-suite/test_stuff/'
'test_classes.py:TestClass.test_failing'),
1)

0 comments on commit 3ab46ec

Please sign in to comment.