-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_recorder doesn't record when there's an exception #705
Comments
@olivierdalang |
The failure may be unrelated to the request, in which case recording it can still make sense (and could for instance allow for faster iterations in solving the failure). In my use case, I was recording an upstream production server's response to capture changes, then adapt the recorded response manually (to keep only items relevant to my test). |
@olivierdalang if you catch the error in your code, will the recorder still fail? |
If the error is catched then there's no unhandled exception, so I think the recorder will work, but the issue is specifically about what happens when there is an exception.
I assumed that too, but it seems that if the function fails, nothing gets recorded at all (see the steps to reproduce in the original report). Note that there may be some misunderstanding on my side as to how this tool is supposed to be used. In #696 I suggested to document a bit more how it is meant to be used (record, then activate to run the test offline, later on update the recorded results, etc.). |
here is the example of what I mean as you can see, you will get a record of c.yaml since we allow decorator to gracefully exit. That represents the real production example that you mentioned from unittest import TestCase
import requests
from responses import _recorder
def actual_function_that_fails():
requests.get("http://example.com", verify=False)
raise AssertionError("Error in assertion")
class MyTestCase(TestCase):
@_recorder.record(file_path="a.yaml")
def test_a(self):
requests.get("http://example.com", verify=False)
@_recorder.record(file_path="b.yaml")
def test_b(self):
actual_function_that_fails()
@_recorder.record(file_path="c.yaml")
def test_c(self):
try:
actual_function_that_fails()
except:
pass |
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
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)
The text was updated successfully, but these errors were encountered: