From 085fb93a8745ffa80aab2d797a9c57594c5e0fea Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Sun, 23 Aug 2026 11:44:00 -0400 Subject: [PATCH] test(logging): stop the location assertion matching the clock (#496) test_location_toggle asserted that ":42" -- a bare colon plus the record's hardcoded lineno -- is absent from a line formatted with include_location=False. But every formatted line starts with an HH:MM:SS.mmm timestamp, so ":42" also matches the clock whenever the minute or the second is 42. The test fails for roughly 3% of runs with nothing wrong: 2026-08-22 08:05:42.274 - INFO - test.logger - hello ^^^ matches ":42" Assert on the whole "module.funcName:lineno" token the format string actually emits ('%(module)s.%(funcName)s:%(lineno)d') instead of a fragment of it. That cannot collide with a timestamp, and it checks the thing the test is named for. Confirmed by formatting a record stamped 08:42:42 -- both minute and second colliding: the old assertion fails, the new one passes. Claude-Session: https://claude.ai/code/session_01STMbQE4YctTacQXfbYqKuW Co-authored-by: Claude Opus 5 (1M context) --- test/test_logging_config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test_logging_config.py b/test/test_logging_config.py index d0cf0fe8..044a5d92 100644 --- a/test/test_logging_config.py +++ b/test/test_logging_config.py @@ -89,11 +89,17 @@ class TestContextualFormatter: assert "hello" in out def test_location_toggle(self): + # Assert on the whole "module.func:lineno" token, not a bare ":42". + # The formatted line starts with an HH:MM:SS timestamp, so a bare + # ":{lineno}" also matches the clock whenever the minute or second + # happens to equal the line number -- about 3% of runs, which is a + # flaky failure with nothing wrong. record = make_record() + location = f"{record.module}.{record.funcName}:{record.lineno}" with_loc = ContextualFormatter(include_location=True).format(record) without = ContextualFormatter(include_location=False).format(record) - assert f":{record.lineno}" in with_loc - assert f":{record.lineno}" not in without + assert location in with_loc + assert location not in without def test_record_not_mutated_no_double_prefix(self): # Regression: a record is formatted once PER HANDLER. The formatter