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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = responses.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: Optional[bool] = 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
Loading