8000 Use httpx_mock in test_httpx (#3967) · orhanhenrik/sentry-python@4ae94a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ae94a5

Browse files
Use httpx_mock in test_httpx (getsentry#3967)
Co-authored-by: Neel Shah <neel.shah@sentry.io>
1 parent a85f0fb commit 4ae94a5

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tests/integrations/httpx/test_httpx.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import httpx
55
import pytest
6-
import responses
76

87
import sentry_sdk
98
from sentry_sdk import capture_message, start_transaction
@@ -16,15 +15,16 @@
1615
"httpx_client",
1716
(httpx.Client(), httpx.AsyncClient()),
1817
)
19-
def test_crumb_capture_and_hint(sentry_init, capture_events, httpx_client):
18+
def test_crumb_capture_and_hint(sentry_init, capture_events, httpx_client, httpx_mock):
19+
httpx_mock.add_response()
20+
2021
def before_breadcrumb(crumb, hint):
2122
crumb["data"]["extra"] = "foo"
2223
return crumb
2324

2425
sentry_init(integrations=[HttpxIntegration()], before_breadcrumb=before_breadcrumb)
2526

2627
url = "http://example.com/"
27-
responses.add(responses.GET, url, status=200)
2828

2929
with start_transaction():
3030
events = capture_events()
@@ -61,11 +61,15 @@ def before_breadcrumb(crumb, hint):
6161
"httpx_client",
6262
(httpx.Client(), httpx.AsyncClient()),
6363
)
64-
def test_outgoing_trace_headers(sentry_init, httpx_client):
65-
sentry_init(traces_sample_rate=1.0, integrations=[HttpxIntegration()])
64+
def test_outgoing_trace_headers(sentry_init, httpx_client, httpx_mock):
65+
httpx_mock.add_response()
66+
67+
sentry_init(
68+
traces_sample_rate=1.0,
69+
integrations=[HttpxIntegration()],
70+
)
6671

6772
url = "http://example.com/"
68-
responses.add(responses.GET, url, status=200)
6973

7074
with start_transaction(
7175
name="/interactions/other-dogs/new-dog",
@@ -93,15 +97,20 @@ def test_outgoing_trace_headers(sentry_init, httpx_client):
9397
"httpx_client",
9498
(httpx.Client(), httpx.AsyncClient()),
9599
)
96-
def test_outgoing_trace_headers_append_to_baggage(sentry_init, httpx_client):
100+
def test_outgoing_trace_headers_append_to_baggage(
101+
sentry_init,
102+
httpx_client,
103+
httpx_mock,
104+
):
105+
httpx_mock.add_response()
106+
97107
sentry_init(
98108
traces_sample_rate=1.0,
99109
integrations=[HttpxIntegration()],
100110
release="d08ebdb9309e1b004c6f52202de58a09c2268e42",
101111
)
102112

103113
url = "http://example.com/"
104-
responses.add(responses.GET, url, status=200)
105114

106115
with start_transaction(
107116
name="/interactions/other-dogs/new-dog",
@@ -290,12 +299,13 @@ def test_do_not_propagate_outside_transaction(sentry_init, httpx_mock):
290299

291300

292301
@pytest.mark.tests_internal_exceptions
293-
def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
302+
def test_omit_url_data_if_parsing_fails(sentry_init, capture_events, httpx_mock):
303+
httpx_mock.add_response()
304+
294305
sentry_init(integrations=[HttpxIntegration()])
295306

296307
httpx_client = httpx.Client()
297308
url = "http://example.com"
298-
responses.add(responses.GET, url, status=200)
299309

300310
events = capture_events()
301311
with mock.patch(
@@ -326,7 +336,9 @@ def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
326336
"httpx_client",
327337
(httpx.Client(), httpx.AsyncClient()),
328338
)
329-
def test_span_origin(sentry_init, capture_events, httpx_client):
339+
def test_span_origin(sentry_init, capture_events, httpx_client, httpx_mock):
340+
httpx_mock.add_response()
341+
330342
sentry_init(
331343
integrations=[HttpxIntegration()],
332344
traces_sample_rate=1.0,
@@ -335,7 +347,6 @@ def test_span_origin(sentry_init, capture_events, httpx_client):
335347
events = capture_events()
336348

337349
url = "http://example.com/"
338-
responses.add(responses.GET, url, status=200)
339350

340351
with start_transaction(name="test_transaction"):
341352
if asyncio.iscoroutinefunction(httpx_client.get):

0 commit comments

Comments
 (0)
0