8000 gh-105539: Explict resource management for connection objects in sqlite3 tests by erlend-aasland · Pull Request #108017 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105539: Explict resource management for connection objects in sqlite3 tests #108017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

erlend-aasland
Copy link
Contributor
@erlend-aasland erlend-aasland commented Aug 16, 2023

@erlend-aasland
Copy link
Contributor Author

This PR either uses the memory_database() resource management helper from Lib/test/test_sqlite3/test_dbapi.py, or introduces explicit resource management via setUp()/tearDown() test case methods.

@erlend-aasland erlend-aasland added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Aug 16, 2023
Copy link
Member
@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

I would suggest moving memory_database() to a new utils.py file. For me, it's surprising that tests import other tests. See for example Lib/test/test_asyncio/utils.py.

8000

@vstinner
Copy link
Member

I don't know the DB API, but I'm surprised that with connect() as db: ... doesn't close the database :-(

- Move test utility functions to util.py
- Use memory database mixin
- Add check() helper for closed connection tests
- Address other remarks by Nikita
@erlend-aasland
Copy link
Contributor Author

I think all your remarks are addressed now; PTAL :)

Copy link
Member
@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

If you want, you can replace from test.test_sqlite3.util import with from .util import.

@erlend-aasland
Copy link
Contributor Author

Thanks for the review, Victor and Nikita!

Copy link
Member
@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

My first sqlite3 PR review ✅

@erlend-aasland erlend-aasland removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Aug 17, 2023
@erlend-aasland erlend-aasland merged commit 1344cfa into python:main Aug 17, 2023
@erlend-aasland erlend-aasland deleted the sqlite/explicit-resource-handling-in-tests branch August 17, 2023 06:46
@erlend-aasland erlend-aasland linked an issue Aug 23, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emit resource warning if sqlite3 fails to close the database
4 participants
0