responses icon indicating copy to clipboard operation
responses copied to clipboard

Fix use of global assert_all_requests_are_fired. Closes #726

Open andrew-cybsafe opened this issue 1 year ago • 4 comments

A somewhat naive fix for the global assert_all_requests_are_fired. Tests are passing locally on 3.12.

andrew-cybsafe avatar Jul 16 '24 16:07 andrew-cybsafe

@markstory can you kick off the tests again?

andrew-cybsafe avatar Jul 18 '24 16:07 andrew-cybsafe

@markstory I think we decided to deprecate this completely a while ago

https://github.com/getsentry/responses?tab=readme-ov-file#deprecations-and-migration-path

beliaev-maksim avatar Jul 25 '24 10:07 beliaev-maksim

I think we decided to deprecate this completely a while ago

@beliaev-maksim the linked doc deprecates responses.assert_all_requests_are_fired for responses.mock.assert_all_requests_are_fired. It's the latter / non-deprecated option that isn't working correctly.

andrew-cybsafe avatar Jul 25 '24 13:07 andrew-cybsafe

it feels like the logic should be moved down to the activate() method. Have you exhausted all the options to make the change self contained within activate ?

@beliaev-maksim The attribute assert_all_requests_are_fired is mocked within the get_wrapped() function regardless of whether a value has been passed into the function. This seems to make it difficult to fix this issue outside of get_wrapped(). I did try only mocking the attribute if the value was passed in, e.g. with this code:

    if assert_all_requests_are_fired is not None:
        assert_mock = std_mock.patch.object(
            target=responses,
            attribute="assert_all_requests_are_fired",
            new=assert_all_requests_are_fired,
        )
    else:
        from contextlib import nullcontext
        assert_mock = nullcontext()

This mostly works except for the test_nested_decorators test, but given I only have a superficial understanding of this code, delving into that is more than I can take on right now.

andrew-cybsafe avatar Aug 10 '24 21:08 andrew-cybsafe