Skip to content
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

Fix use of global assert_all_requests_are_fired. Closes #726 #731

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andrew-cybsafe
Copy link

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

responses/__init__.py Outdated Show resolved Hide resolved
Co-authored-by: Mark Story <[email protected]>
@andrew-cybsafe
Copy link
Author

@markstory can you kick off the tests again?

@beliaev-maksim
Copy link
Collaborator

@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

@andrew-cybsafe
Copy link
Author

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.

Copy link
Collaborator

@beliaev-maksim beliaev-maksim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

@andrew-cybsafe
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants