Repository: getsentry/responses

Issue:
callback results are not unpacked prior to checking for exception bodies
This means the way to mock an error for a callback differs from the way to mock andd error for standard use. Presumably this is not desired - it is not documented at any rate.

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=h1) Report
> Merging [#235](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=desc) into [master](https://codecov.io/gh/getsentry/responses/commit/f89de1bfa616655d6b5fa0e0d5836113357ed986?src=pr&el=desc) will **increase** coverage by `0.35%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/getsentry/responses/pull/235/graphs/tree.svg?width=650&token=x2tAGR7rxE&height=150&src=pr)](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #235      +/-   ##
==========================================
+ Coverage   93.13%   93.48%   +0.35%     
==========================================
  Files           3        3              
  Lines         918      952      +34     
==========================================
+ Hits          855      890      +35     
+ Misses         63       62       -1
```


| [Impacted Files](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [test\_responses.py](https://codecov.io/gh/getsentry/responses/pull/235/diff?src=pr&el=tree#diff-dGVzdF9yZXNwb25zZXMucHk=) | `96.79% <100%> (+0.17%)` | :arrow_up: |
| [responses.py](https://codecov.io/gh/getsentry/responses/pull/235/diff?src=pr&el=tree#diff-cmVzcG9uc2VzLnB5) | `96.65% <100%> (+0.32%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=footer). Last update [f89de1b...895315d](https://codecov.io/gh/getsentry/responses/pull/235?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/responses.py b/responses.py
index 134939a..90bde93 100644
--- a/responses.py
+++ b/responses.py
@@ -390,6 +390,9 @@ class CallbackResponse(BaseResponse):
             raise result
 
         status, r_headers, body = result
+        if isinstance(body, Exception):
+            raise body
+
         body = _handle_body(body)
         headers.update(r_headers)
 


Test patch:
diff --git a/test_responses.py b/test_responses.py
index f202a51..2a085f8 100644
--- a/test_responses.py
+++ b/test_responses.py
@@ -417,6 +417,46 @@ def test_callback():
     assert_reset()
 
 
+def test_callback_exception_result():
+    result = Exception()
+    url = "http://example.com/"
+
+    def request_callback(request):
+        return result
+
+    @responses.activate
+    def run():
+        responses.add_callback(responses.GET, url, request_callback)
+
+        with pytest.raises(Exception) as e:
+            requests.get(url)
+
+        assert e.value is result
+
+    run()
+    assert_reset()
+
+
+def test_callback_exception_body():
+    body = Exception()
+    url = "http://example.com/"
+
+    def request_callback(request):
+        return (200, {}, body)
+
+    @responses.activate
+    def run():
+        responses.add_callback(responses.GET, url, request_callback)
+
+        with pytest.raises(Exception) as e:
+            requests.get(url)
+
+        assert e.value is body
+
+    run()
+    assert_reset()
+
+
 def test_callback_no_content_type():
     body = b"test callback"
     status = 400