Skip to content

Commit 6ea561b

Browse files
committed
Scope sqlite3 patch and apply for Django
Previously the patch was global which caused the django tests to fail if the sqlite3 tests weren't also run.
1 parent 260962a commit 6ea561b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tests/ext/django/test_middleware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aws_xray_sdk.core import xray_recorder, lambda_launcher
77
from aws_xray_sdk.core.context import Context
88
from aws_xray_sdk.core.models import http, facade_segment, segment
9+
from aws_xray_sdk.core import patch
910
from tests.util import get_new_stubbed_recorder
1011
import os
1112

@@ -66,6 +67,7 @@ def test_fault(self):
6667
assert exception.type == 'KeyError'
6768

6869
def test_db(self):
70+
patch(('sqlite3',))
6971
url = reverse('call_db')
7072
self.client.get(url)
7173
segment = xray_recorder.emitter.pop()

tests/ext/sqlite3/test_sqlite3.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from aws_xray_sdk.core import xray_recorder
77
from aws_xray_sdk.core.context import Context
88

9-
patch(('sqlite3',))
10-
db = sqlite3.connect(":memory:")
9+
10+
@pytest.fixture(scope="module")
11+
def db():
12+
patch(('sqlite3',))
13+
return sqlite3.connect(":memory:")
1114

1215

1316
@pytest.fixture(autouse=True)
@@ -24,7 +27,8 @@ def construct_ctx():
2427
xray_recorder.clear_trace_entities()
2528

2629

27-
def test_execute():
30+
def test_execute(db):
31+
2832
q = 'SELECT name FROM sqlite_master'
2933
db.execute(q)
3034

@@ -35,7 +39,8 @@ def test_execute():
3539
assert sql['database_version']
3640

3741

38-
def test_invalid_syntax():
42+
def test_invalid_syntax(db):
43+
db = sqlite3.connect(":memory:")
3944
q = 'some_query'
4045
try:
4146
db.execute(q)

0 commit comments

Comments
 (0)