Skip to content

Commit 0440f02

Browse files
committed
Add basic test that log message extras can be forwarded
1 parent 26ad7b8 commit 0440f02

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/test_logger.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ def test_instrument_connect_message(caplog: LogCaptureFixture) -> None:
301301
assert any(rec.msg == expected_con_mssg for rec in setup_records)
302302

303303

304+
def test_instrument_logger_extra_info(awg5208, caplog: LogCaptureFixture) -> None:
305+
"""
306+
Test that the connect_message method logs as expected
307+
308+
This test kind of belongs both here and in the tests for the instrument
309+
code, but it is more conveniently written here
310+
"""
311+
extra_key = "some_extra"
312+
extra_val = "extra_value"
313+
314+
with caplog.at_level(logging.INFO):
315+
awg5208.visa_log.info("test message")
316+
assert not hasattr(caplog.records[0], extra_key)
317+
caplog.clear()
318+
319+
with caplog.at_level(logging.INFO):
320+
awg5208.visa_log.info("test message", extra={extra_key: extra_val})
321+
assert getattr(caplog.records[0], extra_key) == "extra_value"
322+
323+
304324
def test_installation_info_logging() -> None:
305325
"""
306326
Test that installation information is logged upon starting the logging

0 commit comments

Comments
 (0)