Skip to content

Commit 1291505

Browse files
committed
improv: cover log statement location
1 parent ba3eb2e commit 1291505

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/functional/test_logger.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import io
23
import json
34
import logging
@@ -344,3 +345,17 @@ def test_logger_level_env_var_as_int(monkeypatch):
344345
monkeypatch.setenv("LOG_LEVEL", 50)
345346
with pytest.raises(ValueError, match="Unknown level: '50'"):
346347
Logger()
348+
349+
350+
def test_logger_record_caller_location(stdout):
351+
# GIVEN Logger is initialized
352+
logger = Logger(stream=stdout)
353+
354+
# WHEN log statement is run
355+
logger.info("log")
356+
357+
# THEN 'location' field should have
358+
# the correct caller resolution
359+
caller_fn_name = inspect.currentframe().f_code.co_name
360+
log = capture_logging_output(stdout)
361+
assert caller_fn_name in log["location"]

0 commit comments

Comments
 (0)