Skip to content

Commit

Permalink
Merge pull request #29 from cdent/better-traceback
Browse files Browse the repository at this point in the history
Wrap the http request to trap WSGIAppError and reraise
  • Loading branch information
cdent committed Apr 13, 2015
2 parents d7871e0 + 5b2ac22 commit 1f93d9a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
28 changes: 20 additions & 8 deletions gabbi/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import re
import sys

import wsgi_intercept
import jsonpath_rw
import six
from six.moves.urllib import parse as urlparse
from testtools import testcase

Expand Down Expand Up @@ -243,14 +245,24 @@ def _response_replace(self, message):
self._json_replacer, message)

def _run_request(self, url, method, headers, body):
"""Run the http request and decode output."""

response, content = self.http.request(
url,
method=method,
headers=headers,
body=body
)
"""Run the http request and decode output.
The call to make the request will catch a WSGIAppError from
wsgi_intercept so that the real traceback from a catastrophic
error in the intercepted app can be examined.
"""

try:
response, content = self.http.request(
url,
method=method,
headers=headers,
body=body
)
except wsgi_intercept.WSGIAppError as exc:
# Extract and re-raise the wrapped exception.
six.reraise(exc.exception_type, exc.exception_value,
exc.traceback)

# Set headers and location attributes for follow on requests
self.response = response
Expand Down
10 changes: 8 additions & 2 deletions gabbi/gabbits_intercept/self.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ tests:

- name: bogus method
url: /
method: DIE
method: UNREAL
status: 405
response_headers:
allow: GET, PUT, POST, DELETE, PATCH
x-gabbi-method: DIE
x-gabbi-method: UNREAL
x-gabbi-url: $SCHEME://$NETLOC/

- name: query returned
Expand Down Expand Up @@ -105,3 +105,9 @@ tests:
xfail: true
response_test:
- 'CO"alpha": ["1"]'

- name: test exception wrapper
desc: simple wsgi will raise exception
url: /
xfail: true
method: DIE
3 changes: 3 additions & 0 deletions gabbi/simple_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def __call__(self, environ, start_response):
('X-Gabbi-url', request_url),
]

if request_method == 'DIE':
raise Exception('because you asked me to')

if request_method not in METHODS:
headers.append(
('Allow', ', '.join(METHODS)))
Expand Down
2 changes: 1 addition & 1 deletion test-failskip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Run the tests and confirm that the stuff we expect to skip or fail
# does.

GREP_FAIL_MATCH='expected failures=3'
GREP_FAIL_MATCH='expected failures=4'
GREP_SKIP_MATCH='skips=2'

python setup.py testr && \
Expand Down

0 comments on commit 1f93d9a

Please sign in to comment.