Skip to content

Commit

Permalink
Fix use of global assert_all_requests_are_fired
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-cybsafe committed Jul 16, 2024
1 parent f7a7945 commit 95085f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def get_wrapped(
Wrapped function
"""
if assert_all_requests_are_fired is None:
assert_all_requests_are_fired = mock.assert_all_requests_are_fired
assert_mock = std_mock.patch.object(
target=responses,
attribute="assert_all_requests_are_fired",
Expand Down Expand Up @@ -1014,7 +1016,7 @@ def activate(
func: Optional["_F"] = None,
*,
registry: Optional[Type[Any]] = None,
assert_all_requests_are_fired: bool = False,
assert_all_requests_are_fired: bool | None = None,
) -> Union[Callable[["_F"], "_F"], "_F"]:
if func is not None:
return get_wrapped(func, self)
Expand Down
19 changes: 19 additions & 0 deletions responses/tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,25 @@ def test_some_second_function():
assert_reset()


def test_assert_all_requests_fired_global():
try:
old_value = responses.mock.assert_all_requests_are_fired
responses.mock.assert_all_requests_are_fired = True

@responses.activate
def test_some_function():
# Not all mocks are called so we'll get an AssertionError
responses.add(responses.GET, "http://other_url", json={})
responses.add(responses.GET, "http://some_api", json={})
requests.get("http://some_api")

with pytest.raises(AssertionError):
test_some_function()
assert_reset()
finally:
responses.mock.assert_all_requests_are_fired = old_value


def test_allow_redirects_samehost():
redirecting_url = "http://example.com"
final_url_path = "/1"
Expand Down

0 comments on commit 95085f4

Please sign in to comment.