Skip to content

Commit 8fd8a13

Browse files
chore(ci): add the Middleware Factory feature to nox tests (#4568)
* Adding Middlware Factory test * Addressing Heitor's feedback
1 parent d75b3bf commit 8fd8a13

File tree

8 files changed

+37
-32
lines changed

8 files changed

+37
-32
lines changed

noxfile.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ def test_with_only_required_packages(session: nox.Session):
5252
# Logger
5353
# Metrics - Amazon CloudWatch EMF
5454
# Metrics - Base provider
55+
# Middleware factory without tracer
5556
build_and_run_test(
5657
session,
5758
folders=[
5859
f"{PREFIX_TESTS_FUNCTIONAL}/logger/required_dependencies/",
5960
f"{PREFIX_TESTS_FUNCTIONAL}/metrics/required_dependencies/",
61+
f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/required_dependencies/",
6062
],
6163
)
6264

@@ -78,10 +80,12 @@ def test_with_datadog_as_required_package(session: nox.Session):
7880
def test_with_xray_sdk_as_required_package(session: nox.Session):
7981
"""Tests that depends on AWS XRAY SDK library"""
8082
# Tracer
83+
# Middleware factory with tracer
8184
build_and_run_test(
8285
session,
8386
folders=[
84-
f"{PREFIX_TESTS_FUNCTIONAL}/tracing/aws_xray_sdk/",
87+
f"{PREFIX_TESTS_FUNCTIONAL}/tracer/_aws_xray_sdk/",
88+
f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/_aws_xray_sdk/",
8589
],
8690
extras="tracer",
8791
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
2+
3+
4+
def test_factory_explicit_tracing(monkeypatch):
5+
monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true")
6+
7+
@lambda_handler_decorator(trace_execution=True)
8+
def no_op(handler, event, context):
9+
ret = handler(event, context)
10+
return ret
11+
12+
@no_op
13+
def lambda_handler(evt, ctx):
14+
return True
15+
16+
lambda_handler({}, {})
17+
18+
19+
def test_factory_explicit_tracing_env_var(monkeypatch):
20+
monkeypatch.setenv("POWERTOOLS_TRACE_MIDDLEWARES", "true")
21+
monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true")
22+
23+
@lambda_handler_decorator
24+
def no_op(handler, event, context):
25+
ret = handler(event, context)
26+
return ret
27+
28+
@no_op
29+
def lambda_handler(evt, ctx):
30+
return True
31+
32+
lambda_handler({}, {})

tests/functional/test_middleware_factory.py renamed to tests/functional/middleware_factory/required_dependencies/test_middleware_factory.py

-31
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,6 @@ def lambda_handler(evt, ctx):
6262
lambda_handler({}, {})
6363

6464

65-
def test_factory_explicit_tracing(monkeypatch):
66-
monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true")
67-
68-
@lambda_handler_decorator(trace_execution=True)
69-
def no_op(handler, event, context):
70-
ret = handler(event, context)
71-
return ret
72-
73-
@no_op
74-
def lambda_handler(evt, ctx):
75-
return True
76-
77-
lambda_handler({}, {})
78-
79-
80-
def test_factory_explicit_tracing_env_var(monkeypatch):
81-
monkeypatch.setenv("POWERTOOLS_TRACE_MIDDLEWARES", "true")
82-
monkeypatch.setenv("POWERTOOLS_TRACE_DISABLED", "true")
83-
84-
@lambda_handler_decorator
85-
def no_op(handler, event, context):
86-
ret = handler(event, context)
87-
return ret
88-
89-
@no_op
90-
def lambda_handler(evt, ctx):
91-
return True
92-
93-
lambda_handler({}, {})
94-
95-
9665
def test_factory_decorator_with_kwarg_params(capsys):
9766
@lambda_handler_decorator
9867
def log_event(handler, event, context, log_event=False):

tests/functional/tracer/__init__.py

Whitespace-only changes.

tests/functional/tracer/_aws_xray_sdk/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)