Skip to content

feat: added tests for dir fairness metrics#390

Merged
adolfo-ab merged 3 commits intoopendatahub-io:mainfrom
kpunwatk:fairness_metric
Jun 30, 2025
Merged

feat: added tests for dir fairness metrics#390
adolfo-ab merged 3 commits intoopendatahub-io:mainfrom
kpunwatk:fairness_metric

Conversation

@kpunwatk
Copy link
Copy Markdown
Contributor

This PR Parametrized the existing test cases for DIR Fairness metrics

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

…fairness.py

	modified:   tests/model_explainability/trustyai_service/trustyai_service_utils.py
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 27, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Tests

    • Expanded fairness metric tests to cover both SPD and DIR metrics using parameterized testing, improving test coverage and maintainability.
  • Chores

    • Added a new fairness metric identifier (DIR) to the list of supported metrics.

Walkthrough

The fairness test suite was refactored to support parameterized testing over multiple fairness metrics, specifically SPD and DIR. A new metric identifier "DIR" was added to the fairness metrics class. Test methods were updated to use parameterization, enabling iteration over both metrics in various test scenarios.

Changes

Files/Groups Change Summary
tests/model_explainability/trustyai_service/fairness/test_fairness.py Refactored tests to parameterize over fairness metrics (SPD, DIR) using a new FAIRNESS_METRICS list; updated test method signatures to accept metric_name.
tests/model_explainability/trustyai_service/trustyai_service_utils.py Added "DIR" as a new class attribute to TrustyAIServiceMetrics.Fairness.

Suggested labels

Verified, size/s

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/verified', '/wip', '/hold', '/lgtm', '/cherry-pick', '/build-push-pr-image'}

@kpunwatk
Copy link
Copy Markdown
Contributor Author

/verified

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (9)
tests/model_explainability/trustyai_service/fairness/test_fairness.py (9)

66-74: Update class documentation to reflect multiple metrics.

The docstring still specifically mentions "(spd)" but the class now tests both SPD and DIR metrics due to parameterization.

 class TestFairnessMetricsWithPVCStorage:
     """
-    Verifies all the basic operations with a fairness metric (spd) available in TrustyAI, using PVC storage.
+    Verifies all the basic operations with fairness metrics (SPD, DIR) available in TrustyAI, using PVC storage.
 
     1. Send data to the model and verify that TrustyAI registers the observations.
     2. Apply name mappings
-    3. Send metric request (spd) and verify the response.
+    3. Send metric request and verify the response.
     4. Send metric scheduling request and verify the response.
     5. Send metric deletion request and verify that the scheduled metric has been deleted.
     """

107-117: Fix formatting issues in parameterized test method.

Static analysis detected formatting issues with the method signature.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_with_pvc_storage(
-        self, admin_client, current_client_token, trustyai_service_with_pvc_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_pvc_storage,
+        onnx_loan_model,
+        metric_name,
     ):

119-129: Apply consistent formatting to parameterized test method.

For consistency with the previous suggestion, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_schedule_with_pvc_storage(
-        self, admin_client, current_client_token, trustyai_service_with_pvc_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_pvc_storage,
+        onnx_loan_model,
+        metric_name,
     ):

131-140: Apply consistent formatting to parameterized test method.

For consistency with the previous suggestions, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_prometheus(
-        self, admin_client, model_namespace, trustyai_service_with_pvc_storage, onnx_loan_model, prometheus, metric_name
+        self,
+        admin_client,
+        model_namespace,
+        trustyai_service_with_pvc_storage,
+        onnx_loan_model,
+        prometheus,
+        metric_name,
     ):

142-151: Apply consistent formatting to parameterized test method.

For consistency with the previous suggestions, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_delete_with_pvc_storage(
-        self, admin_client, current_client_token, trustyai_service_with_pvc_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_pvc_storage,
+        onnx_loan_model,
+        metric_name,
     ):

166-175: Update class documentation to reflect multiple metrics.

Similar to the PVC storage class, this docstring should be updated to reflect that multiple metrics are now tested.

 class TestFairnessMetricsWithDBStorage:
     """
-    Verifies all the basic operations with a fairness metric (spd) available in TrustyAI, using MariaDB storage.
+    Verifies all the basic operations with fairness metrics (SPD, DIR) available in TrustyAI, using MariaDB storage.
 
     1. Send data to the model and verify that TrustyAI registers the observations.
     2. Apply name mappings
-    3. Send metric request (spd) and verify the response.
+    3. Send metric request and verify the response.
     4. Send metric scheduling request and verify the response.
     5. Send metric deletion request and verify that the scheduled metric has been deleted.
     """

208-218: Apply consistent formatting to parameterized test method.

For consistency with the PVC storage class methods, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_with_db_storage(
-        self, admin_client, current_client_token, trustyai_service_with_db_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_db_storage,
+        onnx_loan_model,
+        metric_name,
     ):

220-230: Apply consistent formatting to parameterized test method.

For consistency, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_schedule_with_db_storage(
-        self, admin_client, current_client_token, trustyai_service_with_db_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_db_storage,
+        onnx_loan_model,
+        metric_name,
     ):

232-241: Apply consistent formatting to parameterized test method.

For consistency, format the method signature properly.

     @pytest.mark.parametrize("metric_name", FAIRNESS_METRICS)
     def test_fairness_metric_delete_with_db_storage(
-        self, admin_client, current_client_token, trustyai_service_with_db_storage, onnx_loan_model, metric_name
+        self,
+        admin_client,
+        current_client_token,
+        trustyai_service_with_db_storage,
+        onnx_loan_model,
+        metric_name,
     ):
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3d0741 and 00c4c09.

📒 Files selected for processing (2)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (3 hunks)
  • tests/model_explainability/trustyai_service/trustyai_service_utils.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dbasunag
PR: opendatahub-io/opendatahub-tests#338
File: tests/model_registry/rbac/test_mr_rbac.py:24-53
Timestamp: 2025-06-06T12:22:57.057Z
Learning: In the opendatahub-tests repository, prefer keeping test parameterization configurations inline rather than extracting them to separate variables/constants, as it makes triaging easier by avoiding the need to jump between different parts of the file to understand the test setup.
tests/model_explainability/trustyai_service/fairness/test_fairness.py (2)
Learnt from: dbasunag
PR: opendatahub-io/opendatahub-tests#338
File: tests/model_registry/rbac/test_mr_rbac.py:24-53
Timestamp: 2025-06-06T12:22:57.057Z
Learning: In the opendatahub-tests repository, prefer keeping test parameterization configurations inline rather than extracting them to separate variables/constants, as it makes triaging easier by avoiding the need to jump between different parts of the file to understand the test setup.
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
🪛 Flake8 (7.2.0)
tests/model_explainability/trustyai_service/fairness/test_fairness.py

[error] 112-112: continuation line with same indent as next logical line

(E125)


[error] 112-112: whitespace before ')'

(E202)

🪛 Pylint (3.3.7)
tests/model_explainability/trustyai_service/fairness/test_fairness.py

[refactor] 111-111: Too many arguments (6/5)

(R0913)


[refactor] 111-111: Too many positional arguments (6/5)

(R0917)


[refactor] 122-122: Too many arguments (6/5)

(R0913)


[refactor] 122-122: Too many positional arguments (6/5)

(R0917)


[refactor] 134-134: Too many arguments (7/5)

(R0913)


[refactor] 134-134: Too many positional arguments (7/5)

(R0917)


[refactor] 217-217: Too many arguments (6/5)

(R0913)


[refactor] 217-217: Too many positional arguments (6/5)

(R0917)


[refactor] 229-229: Too many arguments (6/5)

(R0913)


[refactor] 229-229: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (2)
tests/model_explainability/trustyai_service/trustyai_service_utils.py (1)

35-35: LGTM! Clean addition of the DIR fairness metric.

The new DIR metric constant follows the same pattern as the existing SPD metric and integrates well with the test parameterization.

tests/model_explainability/trustyai_service/fairness/test_fairness.py (1)

37-37: Good parameterization approach for testing multiple fairness metrics.

The constant definition allows both SPD and DIR metrics to be tested consistently across all test methods. This aligns well with the PR objective of adding DIR fairness metric tests.

@adolfo-ab adolfo-ab merged commit 288178a into opendatahub-io:main Jun 30, 2025
10 checks passed
@github-actions
Copy link
Copy Markdown

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants