getsentry / responses

A utility for mocking out the Python Requests library.
Apache License 2.0
4.08k stars 347 forks source link

_recorder doesn't record when there's an exception #705

Open olivierdalang opened 5 months ago

olivierdalang commented 5 months ago

Describe the bug

When decorating a function with recorder, nothing gets recorded if an exception is thrown in the function.

Additional context

No response

Version of responses

0.24.1

Steps to Reproduce

class MyTestCase(TestCase):

    @_recorder.record(file_path="a.yaml")
    def test_a(self):
        requests.get("https://example.com", verify=False)

    @_recorder.record(file_path="b.yaml")
    def test_b(self):
        requests.get("https://example.com", verify=False)
        self.assertEqual(1, 2) # throws an exception

Expected Result

Requests should be recorded in both tests (files a.yaml and b.yaml should be created)

Actual Result

Requests are only recorded in a (file b.yaml is NOT created)