Repository navigation
pytest: add HH:MM:SS.mmm timestamp prefix to log lines - #15095
Conversation
Nir-Az
left a comment
There was a problem hiding this comment.
Automated Code Review by rs-agentic bot 🤖
Reviewed 1 changed file (). No Copilot reviewer detected — proceeding with automated review.
Overall the change is clean and well-scoped. Inline comments below flag a potential precision bug, a documentation gap, a missing automated test, and a pre-existing robustness issue made more visible by the new timestamps.
|
|
||
| # Shared format for both the per-test FileHandler and the -s live CLI handler. | ||
| # Leading timestamp is wall-clock HH:MM:SS.mmm — date is implicit (one log per test run). | ||
| _LOG_FORMAT = '%(asctime)s.%(msecs)03d -%(levelname).1s- %(message)s' |
There was a problem hiding this comment.
🤖 Auto-generated by rs-agentic bot
Potential Bug: %(msecs)03d truncates instead of rounding
logging.LogRecord.msecs is a float. The %d format specifier in Python %-style formatting converts it to int by truncation (floor), not by rounding. This means a millisecond value of 999.9 will be formatted as 999 instead of rolling over to 1000. In the rare (but real) case where both the truncated and the "true" values straddle a second boundary, consecutive log lines can appear to jump two seconds:
14:42:38.999 ← msecs was 999.9 → truncated to 999
14:42:40.001 ← next second begins
Consider using %(msecs)03.0f instead, which rounds before formatting:
_LOG_FORMAT = '%(asctime)s.%(msecs)03.0f -%(levelname).1s- %(message)s'Or at minimum add a comment noting the intentional truncation.
There was a problem hiding this comment.
Fixed in 50848b4 — switched to %(msecs)03.0f (rounds) and added a comment explaining why %d would truncate. The new infra test test_msecs_rounded_not_truncated locks this in.
|
|
||
| # Shared format for both the per-test FileHandler and the -s live CLI handler. | ||
| # Leading timestamp is wall-clock HH:MM:SS.mmm — date is implicit (one log per test run). | ||
| _LOG_FORMAT = '%(asctime)s.%(msecs)03d -%(levelname).1s- %(message)s' |
There was a problem hiding this comment.
🤖 Auto-generated by rs-agentic bot
Potential Bug: %(msecs)03d truncates instead of rounding
logging.LogRecord.msecs is a float. Python's %d format specifier truncates (floor), not rounds. A value of 999.9 ms is formatted as 999 — not 1000. In the edge case where the truncated value and the true value straddle a second boundary, two consecutive log lines can appear to jump two seconds:
14:42:38.999 ← msecs was 999.9 → truncated to 999
14:42:40.001 ← next log line; looks like 2 s gap
Consider using %(msecs)03.0f instead, which rounds before formatting:
_LOG_FORMAT = '%(asctime)s.%(msecs)03.0f -%(levelname).1s- %(message)s'Or at minimum add a comment noting the intentional truncation to prevent a future reviewer from changing it to %.0f thinking they're "fixing" it.
There was a problem hiding this comment.
Duplicate of the comment above — fixed in 50848b4.
TL;DR
Adds a wall-clock
HH:MM:SS.mmmtimestamp to every pytest log line, in both the per-test log files and the-slive console handler.Why
Failure triage from the per-test
.logartifacts often needs to correlate events across logs (camera comms, frame arrival, hub recycle). Without a timestamp on each line, only relative ordering within one file is visible.What changed
unit-tests/py/rspy/pytest/logging_setup.py:_LOG_FORMAT/_LOG_DATEFMTconstants used by both theFileHandlerformatter and the-slog_cli_format.%(asctime)s.%(msecs)03d -%(levelname).1s- %(message)swithdatefmt='%H:%M:%S'. Date is implicit (one log per test run).Impact audit
LRS_linux_compile_lib_ci.groovy,LRS_windows_compile_pipeline.groovy): the only^-anchored regexes againstpytest-unit-tests.<N>.logmatch either pytest's ownFAILED/ERRORlines (not our formatter) or our bareprint(f"-I- ...")summary lines (which bypass the formatter). CI runs without-s, solog_cli_formatnever fires and no stdlib log lines land in the console log. → No Groovy parser changes needed.unit-tests/infra-tests/): no assertions on log line shape; all 113 pass.Sample
Before:
-I- Test using device: Intel RealSense D455After:
14:42:38.787 -I- Test using device: Intel RealSense D455Test plan
cd unit-tests && python -m pytest infra-tests/ -v→ 113 passed.logfiles showHH:MM:SS.mmm -X- <msg>format