Skip to content

Conversation

@AkhileshNegi
Copy link
Collaborator

@AkhileshNegi AkhileshNegi commented Jan 14, 2026

Summary

The crawler fixture was being imported directly in test files, which linters flagged as an "unused import" since fixtures aren't explicitly called. This led to accidental removal and test failures. Moving the fixture to a conftest.py file follows pytest best practices for fixture discovery and avoids lint false positives

The crawler fixture was being imported directly in test files, which linters
flagged as an "unused import" since fixtures aren't explicitly called. This led
to accidental removal and test failures. Moving the fixture to a conftest.py
file follows pytest best practices for fixture discovery and avoids lint false
positives.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

The changes relocate the crawler pytest fixture from a central utility module to a scope-specific conftest.py file in the documents routes directory. This reduces the fixture's availability to only tests within that directory and removes explicit imports from affected test files.

Changes

Cohort / File(s) Summary
Fixture Relocation
backend/app/tests/api/routes/documents/conftest.py, backend/app/tests/utils/document.py
Added crawler fixture to documents conftest (+11 lines) and removed it from utils module (-6 lines). Fixture now scoped to documents route tests only.
Import Cleanup
backend/app/tests/api/routes/documents/test_route_document_*.py
Removed crawler from import statements across three test files (test_route_document_info.py, test_route_document_list.py, test_route_document_permanent_remove.py). Fixture now auto-discovered via conftest mechanism.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 The crawler hops to its new home,
From utils far, to conftest's zone,
Imports fade as pytest's magic gleams,
Scoped and tidy, just as it seems!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving the crawler fixture to conftest.py following pytest best practices.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py (1)

26-28: Add return type hint to the route fixture.

Per coding guidelines, all functions should have type hints for return values.

Suggested fix
 `@pytest.fixture`
-def route():
+def route() -> Route:
     return Route("")

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00ba869 and 8c7843a.

📒 Files selected for processing (5)
  • backend/app/tests/api/routes/documents/conftest.py
  • backend/app/tests/api/routes/documents/test_route_document_info.py
  • backend/app/tests/api/routes/documents/test_route_document_list.py
  • backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py
  • backend/app/tests/utils/document.py
💤 Files with no reviewable changes (3)
  • backend/app/tests/api/routes/documents/test_route_document_list.py
  • backend/app/tests/utils/document.py
  • backend/app/tests/api/routes/documents/test_route_document_info.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Always add type hints to all function parameters and return values in Python code
Prefix all log messages with the function name in square brackets: logger.info(f"[function_name] Message {mask_string(sensitive_value)}")
Use Python 3.11+ with type hints throughout the codebase

Files:

  • backend/app/tests/api/routes/documents/conftest.py
  • backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py
backend/app/tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Use factory pattern for test fixtures in backend/app/tests/

Files:

  • backend/app/tests/api/routes/documents/conftest.py
  • backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: ProjectTech4DevAI/kaapi-backend PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-17T15:39:30.469Z
Learning: Applies to backend/app/tests/**/*.py : Use factory pattern for test fixtures in `backend/app/tests/`
📚 Learning: 2025-12-17T15:39:30.469Z
Learnt from: CR
Repo: ProjectTech4DevAI/kaapi-backend PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-17T15:39:30.469Z
Learning: Applies to backend/app/tests/**/*.py : Use factory pattern for test fixtures in `backend/app/tests/`

Applied to files:

  • backend/app/tests/api/routes/documents/conftest.py
🧬 Code graph analysis (2)
backend/app/tests/api/routes/documents/conftest.py (3)
backend/app/tests/utils/auth.py (1)
  • TestAuthContext (9-21)
backend/app/tests/utils/document.py (1)
  • WebCrawler (114-128)
backend/app/tests/conftest.py (1)
  • user_api_key (102-104)
backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py (1)
backend/app/tests/utils/document.py (1)
  • DocumentStore (53-80)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: checks (3.12, 6)
🔇 Additional comments (2)
backend/app/tests/api/routes/documents/test_route_document_permanent_remove.py (1)

18-23: Import cleanup looks correct.

The crawler import removal aligns with the fixture now being provided by conftest.py. The remaining imports (DocumentMaker, DocumentStore, Route, WebCrawler) are still needed for direct usage in tests.

backend/app/tests/api/routes/documents/conftest.py (1)

1-11: Good approach moving fixture to conftest.py.

This correctly follows pytest best practices by placing the fixture in conftest.py for automatic discovery, eliminating the need for explicit imports that linters flagged as unused. The WebCrawler class is properly defined as a dataclass with correctly typed fields (client: TestClient and user_api_key: TestAuthContext), and the fixture instantiation pattern matches the dataclass signature. Type hints are properly included throughout, and the fixture implements the factory pattern as required for test fixtures in this directory.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

@AkhileshNegi AkhileshNegi marked this pull request as ready for review January 14, 2026 12:42
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AkhileshNegi AkhileshNegi self-assigned this Jan 14, 2026
@AkhileshNegi AkhileshNegi added the bug Something isn't working label Jan 14, 2026
@AkhileshNegi AkhileshNegi merged commit f72b1d0 into main Jan 14, 2026
3 checks passed
@AkhileshNegi AkhileshNegi deleted the fix/crawler-fixture-conftest branch January 14, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants