Skip to content

Include directory path in pytest log file names - #14939

Merged
Nir-Az merged 9 commits into
realsenseai:developmentfrom
Nir-Az:pytest-log-naming
Apr 21, 2026
Merged

Nir-Az merged 9 commits into
realsenseai:developmentfrom
Nir-Az:pytest-log-naming

Conversation

@Nir-Az

@Nir-Az Nir-Az commented Apr 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Pytest log file names now include directory components (relative to unit-tests/), matching the legacy run-unit-tests.py naming convention
  • e.g. live/frames/pytest-depth.py produces pytest-live-frames-depth.log instead of pytest-depth.log
  • Updated infra tests with new expectations + added coverage for edge cases (no parent dir, single dir, deep nesting, absolute paths)

Test plan

  • All 84 infra tests pass locally
  • [ ]
image

Copilot AI review requested due to automatic review settings April 16, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates pytest per-test log naming to include directory components (relative to unit-tests/) so log filenames match the legacy run-unit-tests.py convention and remain stable for CI artifact linking.

Changes:

  • Update test_log_name() to prepend directory components (joined with -) to the log filename.
  • Update infra tests to match the new naming and add edge-case coverage (root-level tests, single dir, deep nesting, absolute paths).
  • Update internal documentation describing the naming scheme.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
unit-tests/py/rspy/pytest/logging_setup.py Implements directory-aware pytest log filename derivation.
unit-tests/infra-tests/test_log_naming.py Updates expectations and adds edge-case tests for the new naming.
.github/skills/pytest-infra.md Documents the updated log naming convention and examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +254 to +261
# Resolve relative path within the unit-tests tree
normalized = file_path.replace(os.sep, '/')
marker = 'unit-tests/'
idx = normalized.rfind(marker)
if idx >= 0:
rel_path = normalized[idx + len(marker):]
else:
rel_path = normalized

Copilot AI Apr 16, 2026

Copy link

Choose a reason for hiding this comment

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

When unit-tests/ isn't found in file_path, the code falls back to using the entire normalized path. For absolute paths outside the unit-tests tree this will embed large portions of the filesystem path into the log filename (after /→-), which can leak host paths and may exceed filename length limits. Consider falling back to just the file basename (no directory prefix) when the marker isn't found, or compute a safe relative path against _unit_tests_dir/repo root instead of using the full absolute path.

Suggested change
# Resolve relative path within the unit-tests tree
normalized = file_path.replace(os.sep, '/')
marker = 'unit-tests/'
idx = normalized.rfind(marker)
if idx >= 0:
rel_path = normalized[idx + len(marker):]
else:
rel_path = normalized
# Resolve a safe relative path within the unit-tests tree. If the file is
# outside that tree, fall back to just the basename to avoid embedding host
# filesystem paths in the log filename.
abs_file_path = os.path.normpath(os.path.abspath(file_path))
abs_unit_tests_dir = os.path.normpath(os.path.abspath(_unit_tests_dir))
try:
rel_to_unit_tests = os.path.relpath(abs_file_path, abs_unit_tests_dir)
if rel_to_unit_tests == os.curdir or rel_to_unit_tests.startswith('..' + os.sep):
rel_path = os.path.basename(abs_file_path)
else:
rel_path = rel_to_unit_tests
except ValueError:
# Different drive on Windows, or another path normalization failure.
rel_path = os.path.basename(abs_file_path)

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +10
- With device param: pytest-depth.py::test[D455-111] → pytest-live-frames-depth_D455-111.log
- Without device param: pytest-depth.py::test_basic → pytest-live-frames-depth.log

Copilot AI Apr 16, 2026

Copy link

Choose a reason for hiding this comment

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

The docstring examples mix inputs with and without directory prefixes (e.g., “With device param: pytest-depth.py::...” but output includes “pytest-live-frames-...”). Updating the examples to consistently include the same input path form (e.g., live/frames/pytest-depth.py::...) would make the expectations clearer and match the behavior being tested.

Suggested change
- With device param: pytest-depth.py::test[D455-111] → pytest-live-frames-depth_D455-111.log
- Without device param: pytest-depth.py::test_basic → pytest-live-frames-depth.log
- With device param: live/frames/pytest-depth.py::test[D455-111] → pytest-live-frames-depth_D455-111.log
- Without device param: live/frames/pytest-depth.py::test_basic → pytest-live-frames-depth.log

Copilot uses AI. Check for mistakes.
@Nir-Az
Nir-Az requested a review from AviaAv April 16, 2026 17:02

if dirname:
# Strip 'pytest-' prefix, prepend 'pytest-' + dir components joined by '-'
stripped = basename[7:] if basename.startswith('pytest-') else basename

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can basename.startswith('pytest-') ever not happen?

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.

Yes, legacy run-unit-tests also produce logs with test-*.log, right?

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.

Good catch — in production it can't. conftest sets python_files = pytest-*.py, so every collected file starts with pytest-. Dropped the conditional and added a comment explaining it.

# Absolute path outside the unit-tests tree — use basename only to avoid
# embedding host filesystem paths in the log filename.
rel_path = os.path.basename(normalized)
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this branch only happens on the infra tests - please add a comment mentioning this

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.

Added a comment on that else branch clarifying it's only reached by infra test mocks that pass relative paths directly.

@Nir-Az

Nir-Az commented Apr 19, 2026

Copy link
Copy Markdown
Collaborator Author

@AviaAv AviaAv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Nir-Az
Nir-Az merged commit 3991ab9 into realsenseai:development Apr 21, 2026
29 of 30 checks passed
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.

3 participants