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:
parent
aaa9b5bb52
commit
94929992d6
@ -26,11 +26,12 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import unittest
|
||||||
|
from unittest import case
|
||||||
|
|
||||||
import jsonpath_rw
|
import jsonpath_rw
|
||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
from testtools import testcase
|
|
||||||
import wsgi_intercept
|
import wsgi_intercept
|
||||||
|
|
||||||
from gabbi import utils
|
from gabbi import utils
|
||||||
@ -71,14 +72,18 @@ def potentialFailure(func):
|
|||||||
try:
|
try:
|
||||||
func(self)
|
func(self)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise testcase._ExpectedFailure(sys.exc_info())
|
if hasattr(case, '_ExpectedFailure'):
|
||||||
raise testcase._UnexpectedSuccess
|
raise case._ExpectedFailure(sys.exc_info())
|
||||||
|
else:
|
||||||
|
self._addExpectedFailure(self.result, sys.exc_info())
|
||||||
|
else:
|
||||||
|
raise case._UnexpectedSuccess
|
||||||
else:
|
else:
|
||||||
func(self)
|
func(self)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class HTTPTestCase(testcase.TestCase):
|
class HTTPTestCase(unittest.TestCase):
|
||||||
"""Encapsulate a single HTTP request as a TestCase.
|
"""Encapsulate a single HTTP request as a TestCase.
|
||||||
|
|
||||||
If the test is a member of a sequence of requests, ensure that prior
|
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()
|
super(HTTPTestCase, self).tearDown()
|
||||||
self.has_run = True
|
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
|
@potentialFailure
|
||||||
def test_request(self):
|
def test_request(self):
|
||||||
"""Run this request if it has not yet run.
|
"""Run this request if it has not yet run.
|
||||||
|
@ -72,16 +72,26 @@ class ConciseTestResult(TextTestResult):
|
|||||||
desc = test.test_data.get('desc', None)
|
desc = test.test_data.get('desc', None)
|
||||||
return ': '.join((name, desc)) if desc else name
|
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):
|
def printErrorList(self, flavor, errors):
|
||||||
for test, err in errors:
|
for test, err in errors:
|
||||||
self.stream.writeln('%s: %s' % (flavor, self.getDescription(test)))
|
self.stream.writeln('%s: %s' % (flavor, self.getDescription(test)))
|
||||||
# extract details from traceback
|
self.stream.writeln('%s:%s:%s' % (err[0], err[1][0][:70], err[2]))
|
||||||
# XXX: fugly workaround, for lack of a better solution
|
# The rest is left as an exercise for FND
|
||||||
details = str(err)
|
# details = err.strip().splitlines()[-1] # traceback's last line
|
||||||
details = details.strip().splitlines()[-1] # traceback's last line
|
# if ':' in details:
|
||||||
if ':' in details:
|
# details = details.split(':', 1)[1] # discard exception name
|
||||||
details = details.split(':', 1)[1] # discard exception name
|
# if True: # some kind of flag here?
|
||||||
self.stream.writeln('\t%s' % details.strip())
|
# self.stream.writeln('\t%s' % details[:70].strip())
|
||||||
|
# else:
|
||||||
|
# self.stream.writeln('%s' % err)
|
||||||
|
|
||||||
|
|
||||||
class ConciseTestRunner(TextTestRunner):
|
class ConciseTestRunner(TextTestRunner):
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import testtools
|
import unittest
|
||||||
|
|
||||||
from gabbi import fixture
|
from gabbi import fixture
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class FakeFixture(fixture.GabbiFixture):
|
|||||||
self.mock.stop()
|
self.mock.stop()
|
||||||
|
|
||||||
|
|
||||||
class FixtureTest(testtools.TestCase):
|
class FixtureTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(FixtureTest, self).setUp()
|
super(FixtureTest, self).setUp()
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"""Test response handlers.
|
"""Test response handlers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from testtools import matchers
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from gabbi import case
|
from gabbi import case
|
||||||
@ -120,7 +119,6 @@ class HandlersTest(unittest.TestCase):
|
|||||||
self.test.response = {'content-type': 'application/json'}
|
self.test.response = {'content-type': 'application/json'}
|
||||||
with self.assertRaises(AssertionError) as failure:
|
with self.assertRaises(AssertionError) as failure:
|
||||||
self._assert_handler(handler)
|
self._assert_handler(handler)
|
||||||
self.assertIsInstance(failure.exception, matchers.MismatchError)
|
|
||||||
self.assertIn("Expect header content-type with value text/plain,"
|
self.assertIn("Expect header content-type with value text/plain,"
|
||||||
" got application/json",
|
" got application/json",
|
||||||
str(failure.exception))
|
str(failure.exception))
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import testtools
|
import unittest
|
||||||
|
|
||||||
from gabbi import case
|
from gabbi import case
|
||||||
|
|
||||||
|
|
||||||
class EnvironReplaceTest(testtools.TestCase):
|
class EnvironReplaceTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_environ_boolean(self):
|
def test_environ_boolean(self):
|
||||||
"""Environment variables are always strings
|
"""Environment variables are always strings
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
"""Test functions from the utils module.
|
"""Test functions from the utils module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import testtools
|
import unittest
|
||||||
|
|
||||||
from gabbi import utils
|
from gabbi import utils
|
||||||
|
|
||||||
|
|
||||||
class UtilsTest(testtools.TestCase):
|
class UtilsTest(unittest.TestCase):
|
||||||
|
|
||||||
BINARY_TYPES = [
|
BINARY_TYPES = [
|
||||||
'image/png',
|
'image/png',
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
pbr
|
pbr
|
||||||
six
|
six
|
||||||
testtools
|
|
||||||
PyYAML
|
PyYAML
|
||||||
httplib2
|
httplib2
|
||||||
jsonpath-rw
|
jsonpath-rw
|
||||||
|
Loading…
Reference in New Issue
Block a user