Skip to content

Commit

Permalink
Add network hobbling during testing and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
daneah committed Oct 9, 2024
1 parent 7f38693 commit d5baeab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import requests


@pytest.fixture(autouse=True)
def hobble_network(monkeypatch, request):
"""Hobble all network calls made through the requests library"""

if "no_hobble_network" in request.keywords:
return

def hobbled_send(session, request_object, **kwargs):
raise RuntimeError(f"requests hobbled for testing: tried calling {request_object.url}")

monkeypatch.setattr(requests.Session, "send", hobbled_send)
5 changes: 4 additions & 1 deletion tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def stub_response(**kwargs):


class TestEndpoint:
def test_call(self, service):
@mock.patch("requests.Session", autospec=True)
def test_call(self, MockSession, service):
mock_session = MockSession()
mock_session.proxies = {}
service.foo = apiron.Endpoint()
service.foo()

Expand Down

0 comments on commit d5baeab

Please sign in to comment.