summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-09-17 09:09:32 (GMT)
committerGitHub <noreply@github.com>2021-09-17 09:09:32 (GMT)
commitb2b035a949eff1dc54b5bafe2bc9ce72b4d24438 (patch)
tree778d425c06b781da36f0518a16cf4f8351564e14 /Lib/unittest/test
parent773319545ba60577bc140aa46eac83b360240b7a (diff)
downloadcpython-b2b035a949eff1dc54b5bafe2bc9ce72b4d24438.zip
cpython-b2b035a949eff1dc54b5bafe2bc9ce72b4d24438.tar.gz
cpython-b2b035a949eff1dc54b5bafe2bc9ce72b4d24438.tar.bz2
bpo-5846: Fix deprecations for obsolete unittest functions and add tests. (GH-28382)
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_loader.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py
index bc54bf0..90e2081 100644
--- a/Lib/unittest/test/test_loader.py
+++ b/Lib/unittest/test/test_loader.py
@@ -1591,5 +1591,52 @@ class Test_TestLoader(unittest.TestCase):
self.assertEqual(loader.getTestCaseNames(Foo), test_names)
+class TestObsoleteFunctions(unittest.TestCase):
+ class MyTestSuite(unittest.TestSuite):
+ pass
+
+ class MyTestCase(unittest.TestCase):
+ def check_1(self): pass
+ def check_2(self): pass
+ def test(self): pass
+
+ @staticmethod
+ def reverse_three_way_cmp(a, b):
+ return unittest.util.three_way_cmp(b, a)
+
+ def test_getTestCaseNames(self):
+ with self.assertWarns(DeprecationWarning) as w:
+ tests = unittest.getTestCaseNames(self.MyTestCase,
+ prefix='check', sortUsing=self.reverse_three_way_cmp,
+ testNamePatterns=None)
+ self.assertEqual(w.warnings[0].filename, __file__)
+ self.assertEqual(tests, ['check_2', 'check_1'])
+
+ def test_makeSuite(self):
+ with self.assertWarns(DeprecationWarning) as w:
+ suite = unittest.makeSuite(self.MyTestCase,
+ prefix='check', sortUsing=self.reverse_three_way_cmp,
+ suiteClass=self.MyTestSuite)
+ self.assertEqual(w.warnings[0].filename, __file__)
+ self.assertIsInstance(suite, self.MyTestSuite)
+ expected = self.MyTestSuite([self.MyTestCase('check_2'),
+ self.MyTestCase('check_1')])
+ self.assertEqual(suite, expected)
+
+ def test_findTestCases(self):
+ m = types.ModuleType('m')
+ m.testcase_1 = self.MyTestCase
+
+ with self.assertWarns(DeprecationWarning) as w:
+ suite = unittest.findTestCases(m,
+ prefix='check', sortUsing=self.reverse_three_way_cmp,
+ suiteClass=self.MyTestSuite)
+ self.assertEqual(w.warnings[0].filename, __file__)
+ self.assertIsInstance(suite, self.MyTestSuite)
+ expected = [self.MyTestSuite([self.MyTestCase('check_2'),
+ self.MyTestCase('check_1')])]
+ self.assertEqual(list(suite), expected)
+
+
if __name__ == "__main__":
unittest.main()