Skip to content

Conversation

@jonpspri
Copy link
Contributor

@jonpspri jonpspri commented Dec 8, 2025

Summary

  • Add proper engine disposal in pytest_sessionfinish to close all SQLite connections at end of test sessions
  • Use context manager pattern in bootstrap_default_roles() for proper session cleanup
  • Add engine.dispose() calls in test fixtures that create their own engines
  • Remove unused imports in test files

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings December 8, 2025 11:52
Signed-off-by: Jonathan Springer <[email protected]>
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 addresses unclosed SQLite connection warnings during test execution by implementing proper resource cleanup throughout the test suite and application bootstrap code.

Key changes:

  • Added engine.dispose() calls in test fixtures to properly close database connection pools
  • Converted bootstrap_default_roles() to use context manager pattern for automatic session cleanup
  • Added session-level cleanup in pytest_sessionfinish to dispose module-level engine
  • Removed unused imports from test files

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/unit/mcpgateway/utils/test_pagination.py Added engine.dispose() in db_session fixture cleanup; removed unused imports (typing.Any, typing.Dict, unittest.mock.MagicMock, sqlalchemy.orm.Session)
tests/unit/mcpgateway/test_display_name_uuid_features.py Added engine.dispose() in db_session fixture cleanup to close connection pool
tests/conftest.py Implemented pytest_sessionfinish hook to dispose module-level engine; removed unused asyncio import
mcpgateway/bootstrap_db.py Converted bootstrap_default_roles() from manual session management to context manager pattern; added engine.dispose() in main() finally block; removed unused get_db import

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

# This prevents ResourceWarning about unclosed database connections
try:
# First-Party
import mcpgateway.db as db_mod
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

Module 'mcpgateway.db' is imported with both 'import' and 'import from'.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correcting in next push.

Move mcpgateway.db import to module level and remove redundant local
imports for consistency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: Jonathan Springer <[email protected]>
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