Skip to content

Commit 3e19409

Browse files
bpo-45181: Simplify loading sqlite3 tests (GH-28304)
Use unittest discover instead of manually enumerating all test modules and classes. Also add support for filtering them by pattern.
1 parent 9260e67 commit 3e19409

File tree

10 files changed

+14
-146
lines changed

10 files changed

+14
-146
lines changed

Lib/sqlite3/test/backup.py renamed to Lib/sqlite3/test/test_backup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,5 @@ def test_database_source_name(self):
160160
self.verify_backup(bck)
161161

162162

163-
def suite():
164-
return unittest.TestLoader().loadTestsFromTestCase(BackupTests)
165-
166163
if __name__ == "__main__":
167164
unittest.main()

Lib/sqlite3/test/dbapi.py renamed to Lib/sqlite3/test/test_dbapi.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,28 +1156,5 @@ def wait():
11561156
self.assertEqual(proc.returncode, 0)
11571157

11581158

1159-
def suite():
1160-
tests = [
1161-
ClosedConTests,
1162-
ClosedCurTests,
1163-
ConnectionTests,
1164-
ConstructorTests,
1165-
CursorTests,
1166-
ExtensionTests,
1167-
ModuleTests,
1168-
MultiprocessTests,
1169-
OpenTests,
1170-
SqliteOnConflictTests,
1171-
ThreadTests,
1172-
UninitialisedConnectionTests,
1173-
]
1174-
return unittest.TestSuite(
1175-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
1176-
)
1177-
1178-
def test():
1179-
runner = unittest.TextTestRunner()
1180-
runner.run(suite())
1181-
11821159
if __name__ == "__main__":
1183-
test()
1160+
unittest.main()

Lib/sqlite3/test/dump.py renamed to Lib/sqlite3/test/test_dump.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ def __getitem__(self, index):
7070
got = list(self.cx.iterdump())
7171
self.assertEqual(expected, got)
7272

73-
def suite():
74-
tests = [
75-
DumpTests,
76-
]
77-
return unittest.TestSuite(
78-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
79-
)
80-
81-
def test():
82-
runner = unittest.TextTestRunner()
83-
runner.run(suite())
8473

8574
if __name__ == "__main__":
86-
test()
75+
unittest.main()

Lib/sqlite3/test/factory.py renamed to Lib/sqlite3/test/test_factory.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,6 @@ def test_custom(self):
305305
def tearDown(self):
306306
self.con.close()
307307

308-
def suite():
309-
tests = [
310-
ConnectionFactoryTests,
311-
CursorFactoryTests,
312-
RowFactoryTests,
313-
RowFactoryTestsBackwardsCompat,
314-
TextFactoryTests,
315-
TextFactoryTestsWithEmbeddedZeroBytes,
316-
]
317-
return unittest.TestSuite(
318-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
319-
)
320-
321-
def test():
322-
runner = unittest.TextTestRunner()
323-
runner.run(suite())
324308

325309
if __name__ == "__main__":
326-
test()
310+
unittest.main()

Lib/sqlite3/test/hooks.py renamed to Lib/sqlite3/test/test_hooks.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sqlite3 as sqlite
2525

2626
from test.support.os_helper import TESTFN, unlink
27-
from .userfunctions import with_tracebacks
27+
from .test_userfunctions import with_tracebacks
2828

2929
class CollationTests(unittest.TestCase):
3030
def test_create_collation_not_string(self):
@@ -290,19 +290,5 @@ def trace(statement):
290290
self.assertEqual(traced_statements, queries)
291291

292292

293-
def suite():
294-
tests = [
295-
CollationTests,
296-
ProgressTests,
297-
TraceCallbackTests,
298-
]
299-
return unittest.TestSuite(
300-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
301-
)
302-
303-
def test():
304-
runner = unittest.TextTestRunner()
305-
runner.run(suite())
306-
307293
if __name__ == "__main__":
308-
test()
294+
unittest.main()

Lib/sqlite3/test/regression.py renamed to Lib/sqlite3/test/test_regression.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,5 @@ def test_return_empty_bytestring(self):
436436
self.assertEqual(val, b'')
437437

438438

439-
def suite():
440-
tests = [
441-
RegressionTests
442-
]
443-
return unittest.TestSuite(
444-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
445-
)
446-
447-
def test():
448-
runner = unittest.TextTestRunner()
449-
runner.run(suite())
450-
451439
if __name__ == "__main__":
452-
test()
440+
unittest.main()

Lib/sqlite3/test/transactions.py renamed to Lib/sqlite3/test/test_transactions.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,6 @@ def test_transactional_ddl(self):
195195
def tearDown(self):
196196
self.con.close()
197197

198-
def suite():
199-
tests = [
200-
SpecialCommandTests,
201-
TransactionTests,
202-
TransactionalDDL,
203-
]
204-
return unittest.TestSuite(
205-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
206-
)
207-
208-
def test():
209-
runner = unittest.TextTestRunner()
210-
runner.run(suite())
211198

212199
if __name__ == "__main__":
213-
test()
200+
unittest.main()

Lib/sqlite3/test/types.py renamed to Lib/sqlite3/test/test_types.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -530,23 +530,6 @@ def test_date_time_sub_seconds_floating_point(self):
530530
ts2 = self.cur.fetchone()[0]
531531
self.assertEqual(ts, ts2)
532532

533-
def suite():
534-
tests = [
535-
BinaryConverterTests,
536-
ColNamesTests,
537-
CommonTableExpressionTests,
538-
DateTimeTests,
539-
DeclTypesTests,
540-
ObjectAdaptationTests,
541-
SqliteTypeTests,
542-
]
543-
return unittest.TestSuite(
544-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
545-
)
546-
547-
def test():
548-
runner = unittest.TextTestRunner()
549-
runner.run(suite())
550533

551534
if __name__ == "__main__":
552-
test()
535+
unittest.main()

Lib/sqlite3/test/userfunctions.py renamed to Lib/sqlite3/test/test_userfunctions.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -661,22 +661,5 @@ def authorizer_cb(action, arg1, arg2, dbname, source):
661661
return sqlite.SQLITE_OK
662662

663663

664-
def suite():
665-
tests = [
666-
AggregateTests,
667-
AuthorizerIllegalTypeTests,
668-
AuthorizerLargeIntegerTests,
669-
AuthorizerRaiseExceptionTests,
670-
AuthorizerTests,
671-
FunctionTests,
672-
]
673-
return unittest.TestSuite(
674-
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
675-
)
676-
677-
def test():
678-
runner = unittest.TextTestRunner()
679-
runner.run(suite())
680-
681664
if __name__ == "__main__":
682-
test()
665+
unittest.main()

Lib/test/test_sqlite.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import test.support
22
from test.support import import_helper
3+
from test.support import load_package_tests
34

45
# Skip test if _sqlite3 module not installed
56
import_helper.import_module('_sqlite3')
67

78
import unittest
8-
import sqlite3
9-
from sqlite3.test import (dbapi, types, userfunctions,
10-
factory, transactions, hooks, regression,
11-
dump, backup)
9+
import os
10+
import sqlite3.test
1211

13-
def load_tests(*args):
12+
def load_tests(loader, tests, pattern):
1413
if test.support.verbose:
1514
print("test_sqlite: testing with version",
1615
"{!r}, sqlite_version {!r}".format(sqlite3.version,
1716
sqlite3.sqlite_version))
18-
return unittest.TestSuite([dbapi.suite(), types.suite(),
19-
userfunctions.suite(),
20-
factory.suite(), transactions.suite(),
21-
hooks.suite(), regression.suite(),
22-
dump.suite(),
23-
backup.suite()])
17+
return load_package_tests(os.path.dirname(sqlite3.test.__file__), loader, tests, pattern)
2418

2519
if __name__ == "__main__":
2620
unittest.main()

0 commit comments

Comments
 (0)