Skip to content

Dispose SQLAlchemy's engine in storage_tests/test_with_server.py#6330

Merged
Alnusjaponica merged 12 commits intooptuna:masterfrom
kAIto47802:test-with-sercer-dispose-sqlalchemy-engine
Nov 21, 2025
Merged

Dispose SQLAlchemy's engine in storage_tests/test_with_server.py#6330
Alnusjaponica merged 12 commits intooptuna:masterfrom
kAIto47802:test-with-sercer-dispose-sqlalchemy-engine

Conversation

@kAIto47802
Copy link
Copy Markdown
Collaborator

@kAIto47802 kAIto47802 commented Nov 7, 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_with_server.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

  • Make the get_storage funciton contextmanager and use it for all tests in storage_tests/test_with_server.py.

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.

@not522
Copy link
Copy Markdown
Member

not522 commented Nov 12, 2025

@Alnusjaponica @sawa3030 Could you review this PR?

Co-authored-by: Eri Sawada <125344906+sawa3030@users.noreply.github.com>
@kAIto47802 kAIto47802 closed this Nov 19, 2025
@kAIto47802 kAIto47802 deleted the test-with-sercer-dispose-sqlalchemy-engine branch November 19, 2025 06:50
@kAIto47802 kAIto47802 restored the test-with-sercer-dispose-sqlalchemy-engine branch November 19, 2025 06:52
@kAIto47802 kAIto47802 reopened this Nov 19, 2025
@kAIto47802 kAIto47802 closed this Nov 19, 2025
@kAIto47802 kAIto47802 deleted the test-with-sercer-dispose-sqlalchemy-engine branch November 19, 2025 06:58
@kAIto47802 kAIto47802 restored the test-with-sercer-dispose-sqlalchemy-engine branch November 19, 2025 06:59
@kAIto47802 kAIto47802 reopened this Nov 19, 2025
@kAIto47802
Copy link
Copy Markdown
Collaborator Author

Thank you for the comment. I’ve updated the code accordingly.
(I noticed a typo in the branch name and tried to fix it, but the PR was automatically closed during the process, so I have reopened it.)

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 20, 2025
Copy link
Copy Markdown
Contributor

@Alnusjaponica Alnusjaponica left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. LGTM.

@Alnusjaponica Alnusjaponica merged commit 25e478b into optuna:master Nov 21, 2025
28 of 37 checks passed
@Alnusjaponica Alnusjaponica added this to the v4.7.0 milestone Nov 21, 2025
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