Skip to content

[Data] Refactor operator metrics logging tests for improved clarity#57702

Merged
bveeramani merged 1 commit intomasterfrom
refactor-test-stats-operator-metrics
Oct 14, 2025
Merged

[Data] Refactor operator metrics logging tests for improved clarity#57702
bveeramani merged 1 commit intomasterfrom
refactor-test-stats-operator-metrics

Conversation

@bveeramani
Copy link
Copy Markdown
Member

@bveeramani bveeramani commented Oct 14, 2025

This PR refactors the operator metrics logging tests in test_stats.py to improve clarity, reliability, and maintainability.

  • Replaced test_op_metrics_logging and test_op_state_logging with a single, more focused test: test_executor_logs_metrics_on_operator_completion
  • Uses pytest's caplog fixture instead of mocking the logger (more idiomatic)
  • Tests the core behavior (operator completion metrics logged exactly once) without depending on exact log message formatting
  • Eliminates reliance on helper functions and complex string matching
  • More descriptive test name following unit testing best practices
  • Reduced test code complexity while maintaining coverage of critical logging behavior

…ability

Replaced two brittle test functions (test_op_metrics_logging and test_op_state_logging)
with a single, more focused test (test_executor_logs_metrics_on_operator_completion).

Key improvements:
- Uses pytest's caplog fixture instead of mocking the logger, which is more idiomatic
- Tests the core behavior (operator completion metrics logged exactly once) without
  depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following best practices
- Reduced test code complexity while maintaining coverage of critical logging behavior

This change makes the tests more maintainable and less prone to false failures from
minor log format changes.

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
@bveeramani bveeramani requested a review from a team as a code owner October 14, 2025 16:13
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring of the operator metrics logging tests. Replacing the complex, brittle tests with a single, focused test using pytest.caplog significantly improves clarity, reliability, and maintainability. The new test is much easier to understand and correctly focuses on the critical behavior of logging operator completion metrics.

I have one suggestion to make the new test even more robust by verifying that all expected operators in the simple pipeline log their completion, which would fully align the test with its docstring.

Copy link
Copy Markdown
Contributor

@srinathk10 srinathk10 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@bveeramani bveeramani enabled auto-merge (squash) October 14, 2025 16:34
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Oct 14, 2025
@bveeramani bveeramani changed the title Refactor operator metrics logging tests for improved clarity [Data] Refactor operator metrics logging tests for improved clarity Oct 14, 2025
@bveeramani bveeramani merged commit 620dd30 into master Oct 14, 2025
7 checks passed
@bveeramani bveeramani deleted the refactor-test-stats-operator-metrics branch October 14, 2025 17:40
harshit-anyscale pushed a commit that referenced this pull request Oct 15, 2025
This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
…ject#57702)

This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
xinyuangui2 pushed a commit to xinyuangui2/ray that referenced this pull request Oct 22, 2025
…ject#57702)

This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: xgui <xgui@anyscale.com>
elliot-barn pushed a commit that referenced this pull request Oct 23, 2025
This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…ject#57702)

This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
…ject#57702)

This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Future-Outlier pushed a commit to Future-Outlier/ray that referenced this pull request Dec 7, 2025
…ject#57702)

This PR refactors the operator metrics logging tests in `test_stats.py`
to improve clarity, reliability, and maintainability.

- Replaced `test_op_metrics_logging` and `test_op_state_logging` with a
single, more focused test:
`test_executor_logs_metrics_on_operator_completion`
- Uses pytest's `caplog` fixture instead of mocking the logger (more
idiomatic)
- Tests the core behavior (operator completion metrics logged exactly
once) without depending on exact log message formatting
- Eliminates reliance on helper functions and complex string matching
- More descriptive test name following unit testing best practices
- Reduced test code complexity while maintaining coverage of critical
logging behavior

Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu>
Signed-off-by: Future-Outlier <eric901201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants