Skip to content

pytest: add HH:MM:SS.mmm timestamp prefix to log lines - #15095

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
Nir-Az:pytest-log-timestamps
May 25, 2026
Merged

Nir-Az merged 2 commits into
realsenseai:developmentfrom
Nir-Az:pytest-log-timestamps

Conversation

@Nir-Az

@Nir-Az Nir-Az commented May 25, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

Adds a wall-clock HH:MM:SS.mmm timestamp to every pytest log line, in both the per-test log files and the -s live console handler.

Why

Failure triage from the per-test .log artifacts 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:

  • New module-level _LOG_FORMAT / _LOG_DATEFMT constants used by both the FileHandler formatter and the -s log_cli_format.
  • Format: %(asctime)s.%(msecs)03d -%(levelname).1s- %(message)s with datefmt='%H:%M:%S'. Date is implicit (one log per test run).

Impact audit

  • Jenkins Groovy parsers (LRS_linux_compile_lib_ci.groovy, LRS_windows_compile_pipeline.groovy): the only ^-anchored regexes against pytest-unit-tests.<N>.log match either pytest's own FAILED/ERROR lines (not our formatter) or our bare print(f"-I- ...") summary lines (which bypass the formatter). CI runs without -s, so log_cli_format never fires and no stdlib log lines land in the console log. → No Groovy parser changes needed.
  • Infra regression tests (unit-tests/infra-tests/): no assertions on log line shape; all 113 pass.

Sample

Before: -I- Test using device: Intel RealSense D455
After: 14:42:38.787 -I- Test using device: Intel RealSense D455

Test plan

  • cd unit-tests && python -m pytest infra-tests/ -v → 113 passed
  • Manual: per-test .log files show HH:MM:SS.mmm -X- <msg> format
  • Jenkins libci run on this branch

@Nir-Az Nir-Az left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the comment above — fixed in 50848b4.

@Nir-Az
Nir-Az requested a review from OhadMeir May 25, 2026 14:15
@Nir-Az
Nir-Az merged commit c9b9ba0 into realsenseai:development May 25, 2026
29 of 30 checks passed
@Nir-Az
Nir-Az deleted the pytest-log-timestamps branch May 26, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants