Skip to content

Commit 0a37074

Browse files
fix(starlette): updated snapshot tests with latest starlette version (#4238) (#4291)
## Description New version 0.21.0 of Starlette Replaced requests with httpx in TestClient https://www.starlette.io/release-notes/ CI fails due to one of the snapshot tests of starlette verify requests wasn't patched ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] PR cannot be broken up into smaller PRs. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. - [ ] Add to milestone. (cherry picked from commit 8936d35) Co-authored-by: Alberto Vara <[email protected]>
1 parent 538eebf commit 0a37074

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/contrib/starlette/test_starlette.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import httpx
55
import pytest
66
import sqlalchemy
7+
import starlette
78
from starlette.testclient import TestClient
89

910
import ddtrace
@@ -21,6 +22,10 @@
2122
from tests.utils import snapshot
2223

2324

25+
starlette_version_str = getattr(starlette, "__version__", "0.0.0")
26+
starlette_version = tuple([int(i) for i in starlette_version_str.split(".")])
27+
28+
2429
@pytest.fixture
2530
def engine():
2631
sql_patch()
@@ -435,6 +440,9 @@ def test_table_query_snapshot(snapshot_client):
435440
assert r_get.text == "[{'id': 1, 'text': 'test', 'completed': 1}]"
436441

437442

443+
@pytest.mark.skipif(
444+
starlette_version >= (0, 21, 0), reason="Starlette>=0.21.0 replaced requests with httpx in TestClient"
445+
)
438446
@snapshot()
439447
def test_incorrect_patching(run_python_code_in_subprocess):
440448
"""
@@ -450,15 +458,16 @@ def test_incorrect_patching(run_python_code_in_subprocess):
450458
import sqlalchemy
451459
452460
from ddtrace import patch_all
461+
462+
453463
from tests.contrib.starlette.app import get_app
454464
455465
engine = sqlalchemy.create_engine("sqlite:///test.db")
456466
app = get_app(engine)
457467
458468
# Calling patch_all late
459469
# DEV: The test client uses `requests` so we want to ignore them for this scenario
460-
patch_all(requests=False)
461-
470+
patch_all(requests=False, http=False)
462471
with TestClient(app) as test_client:
463472
r = test_client.get("/200")
464473

0 commit comments

Comments
 (0)