Repository navigation
Close the sqlite connections tests leaked - #232
Merged
Merged
Conversation
A coverage run of the suite reported 12 `ResourceWarning: unclosed database` warnings, attributed to whichever test garbage collection happened to run in. Tagging every connection with the test that opened it traced all 12 to three files: - test_vacuum.py (6): `with sqlite3.connect(...)` only commits on exit; it never closes. Wrap in `closing()`. The small-file test now opens in autocommit, as the bloated-db helper already does, so its writes still land without the commit the bare context manager used to supply. - test_cover_hash.py (4): three tests never closed their CoverHashUrlCache, and one read the table back through a bare `with sqlite3.connect`. - test_quota_reserved_skip.py (2): `search()` builds the shared Metron session before the gate check under test, which opened mokkari's SqliteCache (no close) in the developer's real platformdirs cache -- `OnlineSettings()` carries no cache dir, so the conftest's env-var pin does not reach it. Stub `_get_session` in the shared helper, as one test already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A coverage-enabled
make testreported 12ResourceWarning: unclosed database in <sqlite3.Connection>warnings, attributed totest_metron_id_attribute_fallback.pyandtest_write_api.py. That attribution is only where garbage collection happened to run; it moved between runs.To find the openers, a throwaway pytest plugin (not committed) swapped in a
sqlite3.Connectionsubclass that records the opening test and stack, and logs any connection collected while still open. It traced all 12 to three test files. None is a production leak:tests/unit/test_vacuum.pywith sqlite3.connect(...)commits on exit but never closesclosing(...). The small-file test now opens in autocommit, as_make_bloated_dbalready does, so its writes still land without the old implicit committests/unit/test_cover_hash.pyCoverHashUrlCache; one read the table back via a barewith sqlite3.connectcache.close()(the file's existing convention) andclosing(...)tests/unit/test_quota_reserved_skip.pysearch()builds the shared Metron session before the gate check under test, which opened mokkari'sSqliteCache(noclose()in 4.9.0)_get_sessionin the shared_sourcehelper, astest_a_healthy_budget_records_no_reasonalready didHermeticity hole found along the way
The two quota tests opened the developer's real
~/.cache/comicbox/online/metron_cache.sqlite.OnlineSettings()built directly in a test hascache.dir=None, which resolves to the platformdirs cache. The conftest pinsCOMICBOX_ONLINE__CACHE__DIR, but only config-loaded settings read that variable. After this change no test in the suite opens a sqlite file under the real home cache (checked with the same plugin). The hole itself is still there for future tests that buildOnlineSettings()directly.Test plan
make teston currentdevelop+ this commit: 2390 passed, 1 skipped, 0ResourceWarning(was 12). The 5 remaining warnings are pymupdf's SWIGDeprecationWarnings, which predate this change.make fix(no changes),make lint,make tyclean🤖 Generated with Claude Code