Skip to content

Commit 1295bdf

Browse files
committed
Testing for warning log.
1 parent 69a9a01 commit 1295bdf

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/test_config.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from datadog_lambda.config import config
3+
from datadog_lambda.config import config, _get_env
44

55

66
@pytest.fixture
@@ -178,3 +178,30 @@ def test_fips_mode_from_environ(fips_mode, region, conf_val, setenv):
178178
setenv("DD_LAMBDA_FIPS_MODE", fips_mode)
179179
setenv("AWS_REGION", region)
180180
assert config.fips_mode_enabled == conf_val
181+
182+
183+
def test__get_env_does_not_log_when_env_not_set(setenv, monkeypatch):
184+
setenv("TEST_1", None)
185+
setenv("TEST_2", None)
186+
setenv("TEST_3", None)
187+
setenv("TEST_4", None)
188+
189+
class Testing:
190+
test_1 = _get_env("TEST_1")
191+
test_2 = _get_env("TEST_2", "purple")
192+
test_3 = _get_env("TEST_3", "true", bool)
193+
test_4 = _get_env("TEST_4", "true", bool, depends_on_tracing=True)
194+
195+
logs = []
196+
def cap_warn(*args, **kwargs):
197+
logs.append(args)
198+
199+
monkeypatch.setattr("datadog_lambda.config.logger.warning", cap_warn)
200+
201+
testing = Testing()
202+
testing.test_1
203+
testing.test_2
204+
testing.test_3
205+
testing.test_4
206+
207+
assert not logs

0 commit comments

Comments
 (0)