Skip to content

Commit c379ad0

Browse files
committed
Fix unittests.
1 parent 1295ae4 commit c379ad0

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

datadog_lambda/patch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def patch_all():
3030
_patch_for_integration_tests()
3131

3232
if config.trace_enabled:
33-
# XXX this call is making the tests fail
3433
patch_all_dd()
3534
else:
3635
_patch_http()

tests/test_cold_start.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import datadog_lambda.cold_start as cold_start
99
import datadog_lambda.wrapper as wrapper
1010

11+
from tests.utils import get_mock_context
12+
1113

1214
class TestColdStartTracingSetup(unittest.TestCase):
1315
def test_proactive_init(self):
@@ -257,11 +259,7 @@ def finish(span):
257259
def handler(event, context):
258260
import tabnanny
259261

260-
lambda_context = MagicMock()
261-
lambda_context.invoked_function_arn = (
262-
"arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:1"
263-
)
264-
lambda_context.get_remaining_time_in_millis = lambda: 100
262+
lambda_context = get_mock_context()
265263

266264
handler.cold_start_tracing = True
267265
handler({}, lambda_context)

tests/test_patch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
import pytest
12
import unittest
23

34
from unittest.mock import patch, MagicMock
45

56
from datadog_lambda.patch import _patch_http, _ensure_patch_requests
67
from datadog_lambda.constants import TraceHeader
78

9+
from ddtrace.contrib.internal.requests.patch import unpatch as unpatch_requests
10+
11+
12+
@pytest.fixture(scope="module", autouse=True)
13+
def reset_patches():
14+
unpatch_requests()
15+
816

917
class TestPatchHTTPClients(unittest.TestCase):
1018
def setUp(self):

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def get_mock_context(
2222
lambda_context.invoked_function_arn = invoked_function_arn
2323
lambda_context.function_version = function_version
2424
lambda_context.function_name = function_name
25+
lambda_context.get_remaining_time_in_millis = lambda: 100
2526
lambda_context.client_context = ClientContext(custom)
2627
return lambda_context
2728

0 commit comments

Comments
 (0)