Make 3.10 sqlite3 tests run #94998
Description
On my Windows 10, after fresh repository update and debug build, 3.10 sqlite3 tests do not run.
(3.11 and 3.12 are fine.) In 3.10, test_sqlite/ only contains test_dbapi.py
python -m test test_sqlite3 is OK after no tests run. (I though we made this an error.)
python -m test.test_sqlite3 fails because test_sqlite3/ is missing __main__.py, as well as __init__.py
In 3.11, test_sqlite3.__main__.py is
from test.test_sqlite3 import load_tests # Needed for the "load tests" protocol.
import unittest
if __name__ == "__main__":
unittest.main()
The comment seems not needed. The other 3.10 test.test_x directories all run and have variations of this. Some have from . import load_tests. Some have unittest.main('test.test_x') instead of a load_tests import. Most omit the redundant if-clause.
After adding __main__.py, tests still do not run because __init__.py is needed. I may try to do a PR tomorrow.
Activity
terryjreedy commentedon Jul 19, 2022
I copied 3.11
test_sqlite3/__init__.pyinto the 3.10 directory.With
python -m test -v test_sqlite3, the loader runs but fails on line 47def cx_limit(cx, category=sqlite.SQLITE_LIMIT_SQL_LENGTH, limit=128):with an attribute error for SQLITE_LIMIT_SQL_LENGTH.
With the function commented out, python crashes with
Windows fatal exception: access violationin test_connection_bad_reinit at line 572 ,self.assertRaisesRegex(...)line 572. Before that, multiple tests failed, far more than need the commented out function.(Reminder to self: changes on branch sql310.)
pythongh-94998: Make 3.10 sqlite3 tests run
erlend-aasland commentedon Jul 19, 2022
There is no
Lib/test/test_sqlite/directory in the 3.10 branch. However, due to a backport failure (2229d34), there is a partialLib/test/test_sqlite3/directory. This needs to be removed from the 3.10 branch; the sqlite3 tests are found inLib/sqlite3/test/for the 3.10 branch and older.It was added by Brett's request. I'd like to keep it there, as it explains the otherwise apparently unused import.
Tests can be run directly (
./<test-path>on *nix) or via./python -m test <test-name>, so please leave it as it is; it is needed.erlend-aasland commentedon Jul 19, 2022
FTR, sqlite3 tests run as they should in 3.10:
[3.10] pythongh-94998: Remove incorrectly backported Lib/test/test_sq…
erlend-aasland commentedon Jul 19, 2022
Sorry, this may not be obvious, but the sqlite3 tests were moved in 3.11. For 3.10 and older, they all lived in
Lib/sqlite3/test, and were invoked viaLib/test/test_sqlite.py(for example,python -m test test_sqlite). For 3.11, they live inLib/test/test_sqlite3/, and they are now invoked using the correct module name (python -m test test_sqlite3).Perhaps we should add an entry to the 3.11 What's New.
[3.10] gh-94998: Remove incorrectly backported Lib/test/test_sqlite3 …
erlend-aasland commentedon Jul 19, 2022
Fixed with gh-95016; thanks for the report!
terryjreedy commentedon Jul 19, 2022
I wondered whether deleting test_sqlite3/ might be a reasonable alternative. But was not aware that it was a partial duplicate.
The purpose of conditionalizing unittest.main() in x.py is to not call it when x is imported. But main.py is normally only run with
__name__'__main__', when the call is wanted.python -m test test_xyz' only *imports* test_xyz and when it is a directory, only runs itsinit, notmain. This is why the current omission in most such 3.10main`s is not a problem. (But I have no intention of changing anything.)I think all the test directory movements should be mentioned in the corresponding What's New.
erlend-aasland commentedon Jul 19, 2022
Yeah, I think you're right about the
__main__conditional; it is redundant.pythongh-94998: Remove redundant condition in test_sqlite3/__main__.py
gh-94998: Remove redundant condition in test_sqlite3/__main__.py (#95052
pythongh-94998: Remove redundant condition in test_sqlite3/__main__.py (
gh-94998: Remove redundant condition in test_sqlite3/__main__.py (GH-…