Skip to content

Add test coverage for upload_mlflow_artifacts wrapper function#383

Merged
gphuang merged 4 commits intofeat/12-tracelens-integrationfrom
copilot/sub-pr-377-one-more-time
Dec 17, 2025
Merged

Add test coverage for upload_mlflow_artifacts wrapper function#383
gphuang merged 4 commits intofeat/12-tracelens-integrationfrom
copilot/sub-pr-377-one-more-time

Conversation

Copy link

Copilot AI commented Dec 17, 2025

The upload_mlflow_artifacts function in global_vars.py lacked test coverage despite being a coordination wrapper for MLflow artifact uploads.

Changes

  • Added test_global_vars.py with 8 test cases covering:
    • Parameter forwarding to upload_artifacts_to_mlflow (defaults and custom values)
    • Early return when mlflow_writer is None
    • Integration with underlying artifact upload function
    • TraceLens output format options (xlsx, csv, all)
    • Edge cases (empty ranks list, all upload flags disabled)

Test Pattern

@patch("primus.backends.megatron.training.global_vars.get_mlflow_writer")
@patch("primus.backends.megatron.training.global_vars.upload_artifacts_to_mlflow")
def test_none_mlflow_writer_returns_none(mock_upload_artifacts, mock_get_writer):
    mock_get_writer.return_value = None
    
    result = upload_mlflow_artifacts(tensorboard_dir="/path/to/tensorboard")
    
    mock_upload_artifacts.assert_not_called()
    assert result is None

All tests pass. No security issues detected.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 17, 2025 10:24
…ction

Co-authored-by: gphuang <13152353+gphuang@users.noreply.github.com>
…rtions

Co-authored-by: gphuang <13152353+gphuang@users.noreply.github.com>
Co-authored-by: gphuang <13152353+gphuang@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on tracelens integration PR Add test coverage for upload_mlflow_artifacts wrapper function Dec 17, 2025
Copilot AI requested a review from gphuang December 17, 2025 10:30
@gphuang gphuang marked this pull request as ready for review December 17, 2025 11:16
Copilot AI review requested due to automatic review settings December 17, 2025 11:16
@gphuang gphuang merged commit 7da49cc into feat/12-tracelens-integration Dec 17, 2025
2 checks passed
@gphuang gphuang deleted the copilot/sub-pr-377-one-more-time branch December 17, 2025 11:16
Copy link
Contributor

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 comprehensive test coverage for the upload_mlflow_artifacts wrapper function in global_vars.py, which coordinates MLflow artifact uploads but previously lacked any tests.

  • Introduces 8 test cases covering parameter forwarding, early returns, and edge cases
  • Tests verify correct delegation to upload_artifacts_to_mlflow with various parameter combinations
  • Validates handling of disabled MLflow scenarios (when mlflow_writer is None)

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

Comment on lines +116 to +139
@patch("primus.backends.megatron.training.global_vars.get_mlflow_writer")
@patch("primus.backends.megatron.training.global_vars.upload_artifacts_to_mlflow")
def test_none_mlflow_writer_early_return(self, mock_upload_artifacts, mock_get_writer):
"""Test early return when MLflow is not enabled."""
# Setup mock to return None
mock_get_writer.return_value = None

# Call with all parameters set
result = upload_mlflow_artifacts(
tensorboard_dir="/path/to/tensorboard",
exp_root_path="/path/to/exp",
upload_traces=True,
upload_logs=True,
upload_tracelens_report=True,
tracelens_ranks=[0],
tracelens_max_reports=5,
tracelens_output_format="xlsx",
)

# Verify no artifact upload was attempted
mock_upload_artifacts.assert_not_called()

# Verify None is returned immediately
assert result is None
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

This test is redundant with test_none_mlflow_writer_returns_none (lines 96-114). Both tests verify the same behavior: that the function returns None and doesn't call upload_artifacts_to_mlflow when mlflow_writer is None. The only difference is the parameters passed, but since the early return happens before any parameter processing, passing different parameters doesn't test any additional logic. Consider removing this test to reduce maintenance overhead and improve test clarity.

Copilot uses AI. Check for mistakes.
mock_upload_artifacts.return_value = {"traces": 0, "logs": 0, "tracelens_reports": 0}

# Call with empty ranks list
result = upload_mlflow_artifacts(
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Variable result is not used.

Copilot uses AI. Check for mistakes.
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