#17082: test_dbm* now work with unittest test discovery. Patch by Zachary Ware.
authorEzio Melotti <ezio.melotti@gmail.com>
Fri, 1 Mar 2013 09:23:28 +0000 (11:23 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Fri, 1 Mar 2013 09:23:28 +0000 (11:23 +0200)
Lib/test/test_dbm.py
Lib/test/test_dbm_dumb.py
Lib/test/test_dbm_gnu.py
Lib/test/test_dbm_ndbm.py
Misc/NEWS

index 02df7e3cab3c1a1224d05052427197a873bc74bc..752e0b77a6b858545a5d193176ea8b6fd301b0cb 100644 (file)
@@ -34,7 +34,7 @@ def delete_files():
         test.support.unlink(f)
 
 
-class AnyDBMTestCase(unittest.TestCase):
+class AnyDBMTestCase:
     _dict = {'0': b'',
              'a': b'Python:',
              'b': b'Programming',
@@ -119,10 +119,6 @@ class AnyDBMTestCase(unittest.TestCase):
 
 
 class WhichDBTestCase(unittest.TestCase):
-    # Actual test methods are added to namespace after class definition.
-    def __init__(self, *args):
-        unittest.TestCase.__init__(self, *args)
-
     def test_whichdb(self):
         for module in dbm_iterator():
             # Check whether whichdb correctly guesses module name
@@ -169,12 +165,16 @@ class WhichDBTestCase(unittest.TestCase):
         self.d.close()
 
 
-def test_main():
-    classes = [WhichDBTestCase]
+def load_tests(loader, tests, pattern):
+    classes = []
     for mod in dbm_iterator():
-        classes.append(type("TestCase-" + mod.__name__, (AnyDBMTestCase,),
+        classes.append(type("TestCase-" + mod.__name__,
+                            (AnyDBMTestCase, unittest.TestCase),
                             {'module': mod}))
-    test.support.run_unittest(*classes)
+    suites = [unittest.makeSuite(c) for c in classes]
+
+    tests.addTests(suites)
+    return tests
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()
index 6b981c429dfbf8fc62bbdbb5547fcd4c77b594bf..e23392959a823320fb82f4e1b176e57176e87a1c 100644 (file)
@@ -29,9 +29,6 @@ class DumbDBMTestCase(unittest.TestCase):
              '\u00fc'.encode('utf-8') : b'!',
              }
 
-    def __init__(self, *args):
-        unittest.TestCase.__init__(self, *args)
-
     def test_dumbdbm_creation(self):
         f = dumbdbm.open(_fname, 'c')
         self.assertEqual(list(f.keys()), [])
@@ -195,11 +192,6 @@ class DumbDBMTestCase(unittest.TestCase):
     def setUp(self):
         _delete_files()
 
-def test_main():
-    try:
-        support.run_unittest(DumbDBMTestCase)
-    finally:
-        _delete_files()
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()
index 30a39f7b8956502631bd8676b093b9ae71dc2af6..bf6294685a319a022e82ecfa42b230aed6b1b1f7 100755 (executable)
@@ -2,7 +2,7 @@ from test import support
 gdbm = support.import_module("dbm.gnu") #skip if not supported
 import unittest
 import os
-from test.support import verbose, TESTFN, run_unittest, unlink
+from test.support import verbose, TESTFN, unlink
 
 
 filename = TESTFN
@@ -81,8 +81,5 @@ class TestGdbm(unittest.TestCase):
         self.assertTrue(size1 > size2 >= size0)
 
 
-def test_main():
-    run_unittest(TestGdbm)
-
 if __name__ == '__main__':
-    test_main()
+    unittest.main()
index 00dcbd2160e21141d5eb238b5e84595ae08b53f0..f9d3befde9824674cdfaa0605b489e0998945f2c 100755 (executable)
@@ -36,8 +36,5 @@ class DbmTestCase(unittest.TestCase):
             except error:
                 self.fail()
 
-def test_main():
-    support.run_unittest(DbmTestCase)
-
 if __name__ == '__main__':
-    test_main()
+    unittest.main()
index 3149f90852244f297257d75f47f9240e888c40d6..91c415344f0691118dc91e44bb1a85442f81d4fa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -644,6 +644,9 @@ Tests
 
 - Issue #15539: Added regression tests for Tools/scripts/pindent.py.
 
+- Issue #17082: test_dbm* now work with unittest test discovery.
+  Patch by Zachary Ware.
+
 - Issue #17079: test_ctypes now works with unittest test discovery.
   Patch by Zachary Ware.