Skip to content

feat: support log_metric#389

Merged
hfudev merged 1 commit intomainfrom
feat/support-log-metric
Nov 5, 2025
Merged

feat: support log_metric#389
hfudev merged 1 commit intomainfrom
feat/support-log-metric

Conversation

@hfudev
Copy link
Member

@hfudev hfudev commented Nov 5, 2025

No description provided.

@hfudev hfudev requested a review from Copilot November 5, 2025 12:50
@hfudev hfudev self-assigned this Nov 5, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new log_metric fixture that allows users to record performance metrics or numerical data during tests in the Prometheus/OpenMetrics text-based format.

Key changes:

  • New --metric-path CLI option to specify the output file for metrics
  • New log_metric fixture that writes metrics in OpenMetrics format with labels
  • Comprehensive test coverage for both with and without metric path scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pytest-embedded/pytest_embedded/plugin.py Adds --metric-path CLI option and implements metric_path and log_metric fixtures with file locking for thread-safe writes
pytest-embedded/tests/test_base.py Adds test coverage for log_metric functionality with and without metric path
docs/usages/help_functions.rst New documentation file explaining the usage and format of the log_metric fixture

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

Comment on lines +671 to +672
elif os.path.dirname(metric_path):
os.makedirs(os.path.dirname(metric_path), exist_ok=True)
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The condition elif os.path.dirname(metric_path) will be False for paths in the current directory (e.g., 'metrics.txt'), which causes the directory creation to be skipped. This logic should handle the case where the file path is relative and has a non-empty directory component. Consider checking if os.path.dirname(metric_path) is not empty and that directory does not already exist, or use a simpler approach like unconditionally creating the directory if it's not empty.

Suggested change
elif os.path.dirname(metric_path):
os.makedirs(os.path.dirname(metric_path), exist_ok=True)
else:
dir_name = os.path.dirname(metric_path)
if dir_name:
os.makedirs(dir_name, exist_ok=True)

Copilot uses AI. Check for mistakes.
@hfudev hfudev merged commit a7f4999 into main Nov 5, 2025
10 of 11 checks passed
@hfudev hfudev deleted the feat/support-log-metric branch November 5, 2025 14:18
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