Get rid of testtools so we can have sane reporting

testtools turns exceptions into _StringExceptions for unknown
reasons so let's get rid of that.

Then, in gabbi.report lets override exc_info_to_string so we just
don't do that. We want the actual exception information (which is a
tuple of type, exception, tb).

This gets us two things:

* one less dependency
* the ability for @FND to dig at the exception info as he likes,
  which is left as an exercise to him for a followup patch
This commit is contained in:
Chris Dent 2015-07-22 16:12:18 +01:00
parent aaa9b5bb52
commit 94929992d6
7 changed files with 37 additions and 20 deletions

View File

@ -26,11 +26,12 @@ import os
import re
import sys
import time
import unittest
from unittest import case
import jsonpath_rw
import six
from six.moves.urllib import parse as urlparse
from testtools import testcase
import wsgi_intercept
from gabbi import utils
@ -71,14 +72,18 @@ def potentialFailure(func):
try:
func(self)
except Exception:
raise testcase._ExpectedFailure(sys.exc_info())
raise testcase._UnexpectedSuccess
if hasattr(case, '_ExpectedFailure'):
raise case._ExpectedFailure(sys.exc_info())
else:
self._addExpectedFailure(self.result, sys.exc_info())
else:
raise case._UnexpectedSuccess
else:
func(self)
return wrapper
class HTTPTestCase(testcase.TestCase):
class HTTPTestCase(unittest.TestCase):
"""Encapsulate a single HTTP request as a TestCase.
If the test is a member of a sequence of requests, ensure that prior
@ -100,6 +105,11 @@ class HTTPTestCase(testcase.TestCase):
super(HTTPTestCase, self).tearDown()
self.has_run = True
def run(self, result=None):
"""Store the current result handler on this test."""
self.result = result
super(HTTPTestCase, self).run(result)
@potentialFailure
def test_request(self):
"""Run this request if it has not yet run.

View File

@ -72,16 +72,26 @@ class ConciseTestResult(TextTestResult):
desc = test.test_data.get('desc', None)
return ': '.join((name, desc)) if desc else name
def _exc_info_to_string(self, err, test):
"""Override exception to string handling
The default does too much. We don't want doctoring. We want
information!
"""
return err
def printErrorList(self, flavor, errors):
for test, err in errors:
self.stream.writeln('%s: %s' % (flavor, self.getDescription(test)))
# extract details from traceback
# XXX: fugly workaround, for lack of a better solution
details = str(err)
details = details.strip().splitlines()[-1] # traceback's last line
if ':' in details:
details = details.split(':', 1)[1] # discard exception name
self.stream.writeln('\t%s' % details.strip())
self.stream.writeln('%s:%s:%s' % (err[0], err[1][0][:70], err[2]))
# The rest is left as an exercise for FND
# details = err.strip().splitlines()[-1] # traceback's last line
# if ':' in details:
# details = details.split(':', 1)[1] # discard exception name
# if True: # some kind of flag here?
# self.stream.writeln('\t%s' % details[:70].strip())
# else:
# self.stream.writeln('%s' % err)
class ConciseTestRunner(TextTestRunner):

View File

@ -14,7 +14,7 @@
"""
import mock
import testtools
import unittest
from gabbi import fixture
@ -34,7 +34,7 @@ class FakeFixture(fixture.GabbiFixture):
self.mock.stop()
class FixtureTest(testtools.TestCase):
class FixtureTest(unittest.TestCase):
def setUp(self):
super(FixtureTest, self).setUp()

View File

@ -13,7 +13,6 @@
"""Test response handlers.
"""
from testtools import matchers
import unittest
from gabbi import case
@ -120,7 +119,6 @@ class HandlersTest(unittest.TestCase):
self.test.response = {'content-type': 'application/json'}
with self.assertRaises(AssertionError) as failure:
self._assert_handler(handler)
self.assertIsInstance(failure.exception, matchers.MismatchError)
self.assertIn("Expect header content-type with value text/plain,"
" got application/json",
str(failure.exception))

View File

@ -15,12 +15,12 @@
import os
import testtools
import unittest
from gabbi import case
class EnvironReplaceTest(testtools.TestCase):
class EnvironReplaceTest(unittest.TestCase):
def test_environ_boolean(self):
"""Environment variables are always strings

View File

@ -13,12 +13,12 @@
"""Test functions from the utils module.
"""
import testtools
import unittest
from gabbi import utils
class UtilsTest(testtools.TestCase):
class UtilsTest(unittest.TestCase):
BINARY_TYPES = [
'image/png',

View File

@ -1,6 +1,5 @@
pbr
six
testtools
PyYAML
httplib2
jsonpath-rw