1+ import importlib
2+ import sys
3+
14import pytest
25
36from datadog_lambda .config import config , _get_env , Config
@@ -14,6 +17,43 @@ def set_env(key, value):
1417 return set_env
1518
1619
20+ def test_config_import_does_not_import_ddtrace (monkeypatch ):
21+ baseline = set (sys .modules )
22+ import datadog_lambda
23+
24+ with monkeypatch .context () as mp :
25+ for name in list (sys .modules ):
26+ if name == "ddtrace" or name .startswith ("ddtrace." ):
27+ mp .delitem (sys .modules , name , raising = False )
28+
29+ class _BlockDdtrace (importlib .abc .MetaPathFinder ):
30+ def find_spec (self , fullname , path = None , target = None ):
31+ if fullname == "ddtrace" or fullname .startswith ("ddtrace." ):
32+ raise ImportError ("ddtrace must not be imported during this test" )
33+ return None
34+
35+ blocker = _BlockDdtrace ()
36+ mp .setattr (sys , "meta_path" , [blocker ] + sys .meta_path , raising = False )
37+
38+ mp .delattr (datadog_lambda , "config" , raising = False )
39+ mp .delitem (sys .modules , "datadog_lambda.config" , raising = False )
40+ importlib .invalidate_caches ()
41+ importlib .import_module ("datadog_lambda.config" )
42+
43+ assert all (
44+ not (n == "ddtrace" or n .startswith ("ddtrace." )) for n in sys .modules
45+ ), "The config module should not import ddtrace."
46+
47+ introduced = [
48+ n
49+ for n in list (sys .modules )
50+ if (n == "datadog_lambda" or n .startswith ("datadog_lambda." ))
51+ and n not in baseline
52+ ]
53+ for n in introduced :
54+ sys .modules .pop (n , None )
55+
56+
1757def _test_as_bool (env_key , conf_key , default ):
1858 return (
1959 (env_key , conf_key , None , default ),
@@ -72,9 +112,6 @@ def _test_as_list(env_key, conf_key, default):
72112 * _test_as_bool ("DD_INTEGRATION_TEST" , "integration_test" , default = False ),
73113 * _test_as_bool ("DD_BOTOCORE_ADD_SPAN_POINTERS" , "add_span_pointers" , default = True ),
74114 * _test_as_bool ("DD_TRACE_OTEL_ENABLED" , "otel_enabled" , default = False ),
75- * _test_as_bool (
76- "DD_INSTRUMENTATION_TELEMETRY_ENABLED" , "telemetry_enabled" , default = False
77- ),
78115 * _test_as_bool ("DD_MERGE_XRAY_TRACES" , "merge_xray_traces" , default = False ),
79116 * _test_as_bool ("DD_PROFILING_ENABLED" , "profiling_enabled" , default = False ),
80117 * _test_as_bool ("DD_LLMOBS_ENABLED" , "llmobs_enabled" , default = False ),
@@ -86,6 +123,8 @@ def _test_as_list(env_key, conf_key, default):
86123 ),
87124 * _test_as_bool ("DD_LOCAL_TEST" , "local_test" , default = False ),
88125 * _test_as_bool ("DD_DATA_STREAMS_ENABLED" , "data_streams_enabled" , default = False ),
126+ * _test_as_bool ("DD_APPSEC_ENABLED" , "appsec_enabled" , default = False ),
127+ * _test_as_bool ("DD_APPSEC_SCA_ENABLED" , "sca_enabled" , default = False ),
89128 * _test_int (
90129 "DD_CAPTURE_LAMBDA_PAYLOAD_MAX_DEPTH" , "capture_payload_max_depth" , default = 10
91130 ),
@@ -143,9 +182,6 @@ def test_config_from_environ(env_key, conf_key, env_val, conf_val, setenv):
143182 "DD_DECODE_AUTHORIZER_CONTEXT" , "decode_authorizer_context" , default = True
144183 ),
145184 * _test_as_bool ("DD_DATA_STREAMS_ENABLED" , "data_streams_enabled" , default = False ),
146- * _test_as_bool (
147- "DD_INSTRUMENTATION_TELEMETRY_ENABLED" , "telemetry_enabled" , default = False
148- ),
149185)
150186
151187
0 commit comments