Skip to content

Dispose SQLAlchemy's engine in storage_tests/test_cached_storage.py#6337

Merged
c-bata merged 12 commits intooptuna:masterfrom
kAIto47802:dispose-sqlalchemy-engine-test-cached-storage
Nov 28, 2025
Merged

Dispose SQLAlchemy's engine in storage_tests/test_cached_storage.py#6337
c-bata merged 12 commits intooptuna:masterfrom
kAIto47802:dispose-sqlalchemy-engine-test-cached-storage

Conversation

@kAIto47802
Copy link
Copy Markdown
Collaborator

@kAIto47802 kAIto47802 commented Nov 12, 2025

Motivation

This PR is the follow-up on:

and runs in parallel with::

The original PR did not cover all test cases. This PR addresses the remaining ones in storage_tests/test_cached_storage.py.

Important

With these PRs and this PR, all the tests creating RDBStorage in test_storages has been addressed.

The remaining tests creating RDBStorage is only study_tests/test_study_summary.py, which creates the RDBStorage instance for only two times and considered to be less likely to encounter the SQLAlchemy's issue.

Description of the changes

  • Use RDBStorage within a context manager so that storage.engine.dispose() is executed every time.

Note

To ensure that dispose() is always called even when an assert fails, it should be invoked inside __exit__ rather than at the end of the test function.

Important

Most of the diff comes from increased indentation after introducing the context manager.

@y0z
Copy link
Copy Markdown
Member

y0z commented Nov 14, 2025

@fusawa-yugo Could you review this PR?

@c-bata c-bata added the CI Continuous integration. label Nov 21, 2025
@c-bata
Copy link
Copy Markdown
Member

c-bata commented Nov 21, 2025

@sawa3030 Could you review this PR?

@sawa3030
Copy link
Copy Markdown
Collaborator

It’s basically LGTM. I’d appreciate it if you could update the part pointed out here.

kAIto47802 and others added 3 commits November 21, 2025 16:34
Co-authored-by: fusawa-yugo <167162479+fusawa-yugo@users.noreply.github.com>
@kAIto47802
Copy link
Copy Markdown
Collaborator Author

Thank you for the comment. I've update the code accordingly. PTAL :octocat:

Copy link
Copy Markdown
Collaborator

@sawa3030 sawa3030 left a comment

Choose a reason for hiding this comment

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

Thank you for the update. LGTM!

@sawa3030 sawa3030 removed their assignment Nov 27, 2025
@fusawa-yugo
Copy link
Copy Markdown
Contributor

LGTM.
Thank you!

@c-bata c-bata added this to the v4.7.0 milestone Nov 28, 2025
@c-bata c-bata merged commit a3c0d6f into optuna:master Nov 28, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants