Skip to content

Update tests to reduce amount of times py_api fixture is used#293

Merged
PGijsbers merged 7 commits intomainfrom
bypass-client
Mar 27, 2026
Merged

Update tests to reduce amount of times py_api fixture is used#293
PGijsbers merged 7 commits intomainfrom
bypass-client

Conversation

@PGijsbers
Copy link
Copy Markdown
Contributor

Working towards new guidelines for writing tests that provides more structure around when to use the py_api fixture versus calling the methods directly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 18434e54-8a08-40fb-a597-a61b5faa37f9

📥 Commits

Reviewing files that changed from the base of the PR and between 7f588d9 and e16b04e.

📒 Files selected for processing (1)
  • .github/workflows/tests.yml
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/tests.yml

Walkthrough

Tests for OpenML dataset endpoints were reorganized: many HTTP-level integration tests were converted to direct calls against service functions (tag_dataset, list_datasets, get_dataset, get_dataset_features, update_dataset_status), with assertions moved from HTTP responses to return values and raised exceptions. New test modules were added for datasets_get, datasets_features, and datasets_status; the previous HTTP-focused datasets_test module was removed. A few API-route tests remain. No exported/public application symbols were changed.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary objective of the PR: updating tests to reduce py_api fixture usage.
Description check ✅ Passed The description is related to the changeset, explaining the goal of establishing guidelines for py_api fixture usage and test structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bypass-client

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In tests like test_list_uploader you rely on object identity (user is SOME_USER); if SOME_USER is not guaranteed to be a singleton instance this can behave unexpectedly, so consider comparing a stable attribute (e.g. user.id == SOME_USER.id) instead.
  • The new test_rfc9457_error_format only exercises the error handler via DatasetNotFoundError; if the intent is to cover the generic RFC9457 mapping for all dataset-related errors, consider adding at least one route-level example for a different error type (e.g. DatasetNoAccessError) to catch mis-wiring between exception types and the handler.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In tests like `test_list_uploader` you rely on object identity (`user is SOME_USER`); if `SOME_USER` is not guaranteed to be a singleton instance this can behave unexpectedly, so consider comparing a stable attribute (e.g. `user.id == SOME_USER.id`) instead.
- The new `test_rfc9457_error_format` only exercises the error handler via `DatasetNotFoundError`; if the intent is to cover the generic RFC9457 mapping for all dataset-related errors, consider adding at least one route-level example for a different error type (e.g. `DatasetNoAccessError`) to catch mis-wiring between exception types and the handler.

## Individual Comments

### Comment 1
<location path="tests/routers/openml/dataset_tag_test.py" line_range="26" />
<code_context>
 async def test_dataset_tag_rejects_unauthorized(key: ApiKey, py_api: httpx.AsyncClient) -> None:
</code_context>
<issue_to_address>
**suggestion (testing):** Route-level unauthorized tag test no longer asserts the RFC 9457 error payload

Previously, this test verified the RFC 9457 error payload (`content-type`, `type`, and `code` = `AuthenticationFailedError.uri`, `103`); now it only checks the `401` status. Since other tests depend on consistent RFC 9457 formatting, consider keeping at least a minimal assertion on the error `type` and/or `code` so this route still has coverage for the expected problem details without reintroducing heavy `py_api` usage.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

🧹 Nitpick comments (1)
tests/routers/openml/datasets_get_test.py (1)

130-142: Consider separating the xfail case into its own test.

Using pytest.mark.xfail for SOME_USER within a test that expects success for other users conflates two different behaviors (authorized access vs. denied access). If the access control logic changes to allow SOME_USER, this test would silently pass instead of alerting you.

The denied-access scenario is already covered by test_private_dataset_no_access. Consider removing the xfail parameter to keep this test focused on authorized access only.

♻️ Suggested simplification
 `@pytest.mark.parametrize`(
-    "user", [DATASET_130_OWNER, ADMIN_USER, pytest.param(SOME_USER, marks=pytest.mark.xfail)]
+    "user", [DATASET_130_OWNER, ADMIN_USER]
 )
 async def test_private_dataset_access(
     user: User, expdb_test: AsyncConnection, user_test: AsyncConnection
 ) -> None:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/routers/openml/datasets_get_test.py` around lines 130 - 142, The
parameterized test test_private_dataset_access mixes authorized-success cases
and an xfail for SOME_USER; remove the pytest.param(SOME_USER,
marks=pytest.mark.xfail) entry so the test only asserts successful access for
DATASET_130_OWNER and ADMIN_USER, and if you still need to assert denied access
for SOME_USER keep or extend the separate test_private_dataset_no_access test to
cover that scenario instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/routers/openml/datasets_get_test.py`:
- Around line 130-142: The parameterized test test_private_dataset_access mixes
authorized-success cases and an xfail for SOME_USER; remove the
pytest.param(SOME_USER, marks=pytest.mark.xfail) entry so the test only asserts
successful access for DATASET_130_OWNER and ADMIN_USER, and if you still need to
assert denied access for SOME_USER keep or extend the separate
test_private_dataset_no_access test to cover that scenario instead.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3af1919e-f663-4f31-a747-c2927b777e83

📥 Commits

Reviewing files that changed from the base of the PR and between a4f5cdc and 7f588d9.

📒 Files selected for processing (5)
  • tests/routers/openml/datasets_features_test.py
  • tests/routers/openml/datasets_get_test.py
  • tests/routers/openml/datasets_list_datasets_test.py
  • tests/routers/openml/datasets_status_test.py
  • tests/routers/openml/datasets_test.py
💤 Files with no reviewable changes (1)
  • tests/routers/openml/datasets_test.py

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.15%. Comparing base (fde90bf) to head (e16b04e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #293   +/-   ##
=======================================
  Coverage   54.15%   54.15%           
=======================================
  Files          37       37           
  Lines        1553     1553           
  Branches      135      135           
=======================================
  Hits          841      841           
  Misses        710      710           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PGijsbers PGijsbers merged commit c68a836 into main Mar 27, 2026
9 checks passed
@PGijsbers PGijsbers deleted the bypass-client branch March 27, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant