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.
This commit is contained in:
Serhiy Storchaka 2021-09-13 14:16:26 +03:00 committed by GitHub
parent 9260e67398
commit 3e19409d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 146 deletions

View file

@ -160,8 +160,5 @@ class BackupTests(unittest.TestCase):
self.verify_backup(bck)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(BackupTests)
if __name__ == "__main__":
unittest.main()

View file

@ -1156,28 +1156,5 @@ class MultiprocessTests(unittest.TestCase):
self.assertEqual(proc.returncode, 0)
def suite():
tests = [
ClosedConTests,
ClosedCurTests,
ConnectionTests,
ConstructorTests,
CursorTests,
ExtensionTests,
ModuleTests,
MultiprocessTests,
OpenTests,
SqliteOnConflictTests,
ThreadTests,
UninitialisedConnectionTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -70,17 +70,6 @@ class DumpTests(unittest.TestCase):
got = list(self.cx.iterdump())
self.assertEqual(expected, got)
def suite():
tests = [
DumpTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -305,22 +305,6 @@ class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase):
def tearDown(self):
self.con.close()
def suite():
tests = [
ConnectionFactoryTests,
CursorFactoryTests,
RowFactoryTests,
RowFactoryTestsBackwardsCompat,
TextFactoryTests,
TextFactoryTestsWithEmbeddedZeroBytes,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -24,7 +24,7 @@ import unittest
import sqlite3 as sqlite
from test.support.os_helper import TESTFN, unlink
from .userfunctions import with_tracebacks
from .test_userfunctions import with_tracebacks
class CollationTests(unittest.TestCase):
def test_create_collation_not_string(self):
@ -290,19 +290,5 @@ class TraceCallbackTests(unittest.TestCase):
self.assertEqual(traced_statements, queries)
def suite():
tests = [
CollationTests,
ProgressTests,
TraceCallbackTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -436,17 +436,5 @@ class RegressionTests(unittest.TestCase):
self.assertEqual(val, b'')
def suite():
tests = [
RegressionTests
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -195,19 +195,6 @@ class TransactionalDDL(unittest.TestCase):
def tearDown(self):
self.con.close()
def suite():
tests = [
SpecialCommandTests,
TransactionTests,
TransactionalDDL,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -530,23 +530,6 @@ class DateTimeTests(unittest.TestCase):
ts2 = self.cur.fetchone()[0]
self.assertEqual(ts, ts2)
def suite():
tests = [
BinaryConverterTests,
ColNamesTests,
CommonTableExpressionTests,
DateTimeTests,
DeclTypesTests,
ObjectAdaptationTests,
SqliteTypeTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()

View file

@ -661,22 +661,5 @@ class AuthorizerLargeIntegerTests(AuthorizerTests):
return sqlite.SQLITE_OK
def suite():
tests = [
AggregateTests,
AuthorizerIllegalTypeTests,
AuthorizerLargeIntegerTests,
AuthorizerRaiseExceptionTests,
AuthorizerTests,
FunctionTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
unittest.main()