Skip to content

Commit bfe3404

Browse files
committed
improv(tracer): test auto patch method
1 parent 250e47f commit bfe3404

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

python/tests/unit/test_tracing.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest import mock
2+
13
import pytest
24

35
from aws_lambda_powertools.tracing import Tracer
@@ -127,3 +129,27 @@ def handler(event, context):
127129

128130
assert put_annotation_mock.call_count == 1
129131
assert put_annotation_mock.call_args == mocker.call(key=annotation_key, value=annotation_value)
132+
133+
@mock.patch('aws_lambda_powertools.tracing.Tracer.patch')
134+
def test_tracer_autopatch(patch_mock):
135+
# GIVEN tracer is instantiated
136+
# WHEN default options were used, or patch() was called
137+
# THEN tracer should patch all modules
138+
tracer_a = Tracer(disabled=True)
139+
140+
assert patch_mock.call_count == 1
141+
142+
tracer_b = Tracer(disabled=True, auto_patch=False)
143+
tracer_b.patch()
144+
145+
assert patch_mock.call_count == 2
146+
147+
@mock.patch('aws_lambda_powertools.tracing.Tracer.patch')
148+
def test_tracer_no_autopatch(patch_mock):
149+
# GIVEN tracer is instantiated
150+
# WHEN auto_patch is disabled
151+
# THEN tracer should not patch any module
152+
tracer_a = Tracer(disabled=True, auto_patch=False)
153+
tracer_b = tracer_a.instance()
154+
155+
assert patch_mock.call_count == 0

0 commit comments

Comments
 (0)