Skip to content

Refactor setups_tag tests to use direct method calls for non-happy-path tests#298

Open
igennova wants to merge 2 commits intoopenml:mainfrom
igennova:refactor/setups-tag-tests-direct-calls
Open

Refactor setups_tag tests to use direct method calls for non-happy-path tests#298
igennova wants to merge 2 commits intoopenml:mainfrom
igennova:refactor/setups-tag-tests-direct-calls

Conversation

@igennova
Copy link
Copy Markdown
Contributor

@igennova igennova commented Mar 27, 2026

Summary:

Following the testing guidelines from #295:

  • Keep one happy-path test via py_api .
  • Convert error/variation tests to direct calls to tag_setup() .
  • Add a direct-call success test .

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Walkthrough

Tests in tests/routers/openml/setups_tag_test.py were refactored to call routers.openml.setups.tag_setup directly instead of exercising the /setup/tag HTTP endpoint for most cases. The "unknown setup" test now asserts SetupNotFoundError is raised with a matching message; the "already exists" test pre-inserts a conflicting setup_tag row and asserts TagAlreadyExistsError; the "success" unit test validates the returned payload and database persistence via a parametrized SQL query. A separate HTTP-based success test marked with @pytest.mark.mut remains. Regex import and prior re.match usage were removed.

Possibly related PRs

Suggested labels

tests

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 describes the main change: refactoring test cases to use direct method calls instead of HTTP endpoints for non-happy-path tests.
Description check ✅ Passed The pull request description accurately describes the refactoring effort: converting non-happy-path tests to direct calls to tag_setup() and keeping one HTTP-based happy-path test, which aligns with the detailed changeset summary.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 the success tests you assert "my_*_tag" in ...["tag"]; if the tag is expected to match exactly, consider changing these to strict equality to catch unexpected formatting or concatenation issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the success tests you assert `"my_*_tag" in ...["tag"]`; if the tag is expected to match exactly, consider changing these to strict equality to catch unexpected formatting or concatenation issues.

## Individual Comments

### Comment 1
<location path="tests/routers/openml/setups_tag_test.py" line_range="29-30" />
<code_context>
-    assert re.match(r"Setup \d+ not found.", response.json()["detail"])
+
+    assert response.status_code == HTTPStatus.OK
+    assert "my_new_success_api_tag" in response.json()["setup_tag"]["tag"]
+
+    rows = await expdb_test.execute(
</code_context>
<issue_to_address>
**suggestion (testing):** Use stricter equality assertions for tags instead of substring checks.

Both the API success test and the direct success test use `in` to check the tag value. If the API doesn’t intentionally add extra content around the tag, please assert the exact value (or full structure) instead, e.g.:

```python
assert response.json()["setup_tag"]["tag"] == "my_new_success_api_tag"
```

This makes the tests stricter and prevents false positives if additional text is ever added to the tag.

```suggestion
    assert response.status_code == HTTPStatus.OK
    assert response.json()["setup_tag"]["tag"] == "my_new_success_api_tag"
```
</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.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.20%. Comparing base (a8354de) to head (ee61275).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #298   +/-   ##
=======================================
  Coverage   54.20%   54.20%           
=======================================
  Files          38       38           
  Lines        1581     1581           
  Branches      137      137           
=======================================
  Hits          857      857           
  Misses        722      722           
  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.

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 (2)
tests/routers/openml/setups_tag_test.py (2)

42-42: Tighten exception regex to avoid permissive matches.

Both patterns currently end with . (any char in regex) and are unanchored, so they can pass on unintended messages. Use anchored patterns and escape the final period.

Proposed assertion pattern fix
-    with pytest.raises(SetupNotFoundError, match=r"Setup \d+ not found."):
+    with pytest.raises(SetupNotFoundError, match=r"^Setup \d+ not found\.$"):
...
-    with pytest.raises(TagAlreadyExistsError, match=r"Setup 1 already has tag 'existing_tag_123'."):
+    with pytest.raises(
+        TagAlreadyExistsError,
+        match=r"^Setup 1 already has tag 'existing_tag_123'\.$",
+    ):

Also applies to: 56-56

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/routers/openml/setups_tag_test.py` at line 42, The regex in the
pytest.raises calls for SetupNotFoundError is too permissive — update the match
patterns used in the pytest.raises(SetupNotFoundError, match=...) assertions to
anchor the start and end and escape the final period (e.g., change to a pattern
equivalent to "^Setup \\d+ not found\\.$"); apply the same anchored/escaped fix
to the other similar assertion referenced (the second pytest.raises at the other
location) so the tests only match the exact expected messages.

32-35: Prefer bound SQL parameters in DB assertions.

Inline SQL string literals are brittle for tags with quotes and harder to reuse; parameterized text(...) keeps the assertions safer and clearer.

Proposed query refactor
-    rows = await expdb_test.execute(
-        text("SELECT * FROM setup_tag WHERE id = 1 AND tag = 'my_new_success_api_tag'")
-    )
+    rows = await expdb_test.execute(
+        text("SELECT * FROM setup_tag WHERE id = :setup_id AND tag = :tag"),
+        {"setup_id": 1, "tag": "my_new_success_api_tag"},
+    )
...
-    rows = await expdb_test.execute(
-        text("SELECT * FROM setup_tag WHERE id = 1 AND tag = 'my_direct_success_tag'")
-    )
+    rows = await expdb_test.execute(
+        text("SELECT * FROM setup_tag WHERE id = :setup_id AND tag = :tag"),
+        {"setup_id": 1, "tag": "my_direct_success_tag"},
+    )

Also applies to: 75-78

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/routers/openml/setups_tag_test.py` around lines 32 - 35, Replace the
inline SQL literals in the test DB assertions with parameterized SQL using
text(...) and bound parameters: update the expdb_test.execute calls that query
the setup_tag table (currently using "id = 1 AND tag =
'my_new_success_api_tag'") to use named bind params (e.g., :id, :tag) and pass
the values in the execute call (e.g., {"id": 1, "tag":
"my_new_success_api_tag"}); make the same change for the other assertion that
queries setup_tag (the second expdb_test.execute around the later assertion) so
both queries use bound parameters instead of inline string literals.
🤖 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/setups_tag_test.py`:
- Line 42: The regex in the pytest.raises calls for SetupNotFoundError is too
permissive — update the match patterns used in the
pytest.raises(SetupNotFoundError, match=...) assertions to anchor the start and
end and escape the final period (e.g., change to a pattern equivalent to "^Setup
\\d+ not found\\.$"); apply the same anchored/escaped fix to the other similar
assertion referenced (the second pytest.raises at the other location) so the
tests only match the exact expected messages.
- Around line 32-35: Replace the inline SQL literals in the test DB assertions
with parameterized SQL using text(...) and bound parameters: update the
expdb_test.execute calls that query the setup_tag table (currently using "id = 1
AND tag = 'my_new_success_api_tag'") to use named bind params (e.g., :id, :tag)
and pass the values in the execute call (e.g., {"id": 1, "tag":
"my_new_success_api_tag"}); make the same change for the other assertion that
queries setup_tag (the second expdb_test.execute around the later assertion) so
both queries use bound parameters instead of inline string literals.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bd2301c9-25fe-43e9-abd7-cc6ab9b01255

📥 Commits

Reviewing files that changed from the base of the PR and between a8354de and 386da4c.

📒 Files selected for processing (1)
  • tests/routers/openml/setups_tag_test.py

@igennova
Copy link
Copy Markdown
Contributor Author

@PGijsbers This PR refactors setups_tag tests per the post-#295 structure (single HTTP happy path + direct handler calls). I plan to open additional small PRs for other endpoints the same way unless you’d prefer a different split.

Thanks

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.

1 participant