Skip to content

Commit c74934d

Browse files
chore(serverless): remove flaky mark from two serverless tests [backport 3.4] (#13111)
Backport 612d802 from #13039 to 3.4. This PR addresses two flaky tests in `tests/contrib/aws_lambda/test_aws_lambda.py`. The issue that needed fixing was that env vars are checked during patch/unpatch. Since unpatch was being called after the env was reset, they were never being unpatched correctly. This PR ensures that the patching and unpatching occurs within the env override. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Rey Abolofia <[email protected]>
1 parent af255f0 commit c74934d

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

tests/contrib/aws_lambda/test_aws_lambda.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
13
import pytest
24

35
from ddtrace.contrib.internal.aws_lambda.patch import patch
@@ -11,7 +13,6 @@
1113
from tests.contrib.aws_lambda.handlers import manually_wrapped_handler
1214
from tests.contrib.aws_lambda.handlers import static_handler
1315
from tests.contrib.aws_lambda.handlers import timeout_handler
14-
from tests.utils import flaky
1516
from tests.utils import override_env
1617

1718

@@ -46,13 +47,15 @@ def get_env(env=None):
4647
return {**common_env, **env}
4748

4849

49-
@pytest.fixture(autouse=True)
50-
def setup():
51-
yield
52-
unpatch()
50+
@contextlib.contextmanager
51+
def override_env_and_patch(env):
52+
# patching and unpatching must be done while the environment is set
53+
with override_env(env):
54+
patch()
55+
yield
56+
unpatch()
5357

5458

55-
@flaky(1744053478)
5659
@pytest.mark.parametrize("customApmFlushDeadline", [("-100"), ("10"), ("100"), ("200")])
5760
@pytest.mark.snapshot
5861
def test_timeout_traces(context, customApmFlushDeadline):
@@ -64,9 +67,7 @@ def test_timeout_traces(context, customApmFlushDeadline):
6467
}
6568
)
6669

67-
with override_env(env):
68-
patch()
69-
70+
with override_env_and_patch(env):
7071
datadog(timeout_handler)({}, context())
7172

7273

@@ -83,9 +84,7 @@ def test_continue_on_early_trace_ending(context):
8384
}
8485
)
8586

86-
with override_env(env):
87-
patch()
88-
87+
with override_env_and_patch(env):
8988
datadog(finishing_spans_early_handler)({}, context())
9089

9190

@@ -98,11 +97,8 @@ async def test_file_patching(context):
9897
}
9998
)
10099

101-
with override_env(env):
102-
patch()
103-
100+
with override_env_and_patch(env):
104101
result = datadog(handler)({}, context())
105-
106102
assert result == {"success": True}
107103

108104

@@ -117,11 +113,8 @@ async def test_module_patching(mocker, context):
117113
}
118114
)
119115

120-
with override_env(env):
121-
patch()
122-
116+
with override_env_and_patch(env):
123117
result = manually_wrapped_handler({}, context())
124-
125118
assert result == {"success": True}
126119

127120

@@ -135,7 +128,6 @@ async def test_module_patching(mocker, context):
135128
],
136129
)
137130
@pytest.mark.snapshot
138-
@flaky(1744053478, reason="Did not receive expected traces: 'aws.lambda' for [handler3-instance_handler_with_code]")
139131
def test_class_based_handlers(context, handler, function_name):
140132
env = get_env(
141133
{
@@ -144,8 +136,6 @@ def test_class_based_handlers(context, handler, function_name):
144136
}
145137
)
146138

147-
with override_env(env):
148-
patch()
149-
139+
with override_env_and_patch(env):
150140
result = datadog(handler)({}, context())
151141
assert result == {"success": True}

0 commit comments

Comments
 (0)