From 2510745de42d67636bd9e9e54d3c1b513087a6f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 4 Jul 2026 23:19:51 +0000 Subject: [PATCH] Add --sqlite-autocommit pytest option Runs the entire test suite against connections created with the Python 3.12+ sqlite3.connect(autocommit=True) mode, by patching connect() to default autocommit=True for internally-created connections. Errors on older Python versions. The full suite passes in both modes with no test changes. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd --- tests/conftest.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 6fd35b8..728db7b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,11 +8,36 @@ create table Gosh2 (c1 text, c2 text, c3 text); """ +def pytest_addoption(parser): + parser.addoption( + "--sqlite-autocommit", + action="store_true", + default=False, + help=( + "Run every test against connections created with the Python 3.12+ " + "sqlite3.connect(autocommit=True) mode" + ), + ) + + def pytest_configure(config): import sys sys._called_from_test = True # type: ignore[attr-defined] + if config.getoption("--sqlite-autocommit"): + if sys.version_info < (3, 12): + raise pytest.UsageError( + "--sqlite-autocommit requires Python 3.12 or higher" + ) + real_connect = sqlite3.connect + + def autocommit_connect(*args, **kwargs): + kwargs.setdefault("autocommit", True) + return real_connect(*args, **kwargs) + + sqlite3.connect = autocommit_connect + @pytest.fixture(autouse=True) def close_all_databases():