summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2009-09-13 17:28:35 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2009-09-13 17:28:35 (GMT)
commit5a9719d62745a8eed14b5084c2bdb16bf5cb8011 (patch)
treee44c845567849c3df63ce14a52362c94759f36eb /Lib/test
parentee2df0300933e8a21372baae01ad2cf2e60a0282 (diff)
downloadcpython-5a9719d62745a8eed14b5084c2bdb16bf5cb8011.zip
cpython-5a9719d62745a8eed14b5084c2bdb16bf5cb8011.tar.gz
cpython-5a9719d62745a8eed14b5084c2bdb16bf5cb8011.tar.bz2
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_unittest.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index 2fab7de..79ee982 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -555,6 +555,47 @@ class Test_TestLoader(TestCase):
self.assertEqual(list(suite), [testcase_1])
# "The specifier name is a ``dotted name'' that may resolve ... to
+ # ... a callable object which returns a TestCase ... instance"
+ #*****************************************************************
+ #Override the suiteClass attribute to ensure that the suiteClass
+ #attribute is used
+ def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(self):
+ class SubTestSuite(unittest.TestSuite):
+ pass
+ m = types.ModuleType('m')
+ testcase_1 = unittest.FunctionTestCase(lambda: None)
+ def return_TestCase():
+ return testcase_1
+ m.return_TestCase = return_TestCase
+
+ loader = unittest.TestLoader()
+ loader.suiteClass = SubTestSuite
+ suite = loader.loadTestsFromName('return_TestCase', m)
+ self.assertTrue(isinstance(suite, loader.suiteClass))
+ self.assertEqual(list(suite), [testcase_1])
+
+ # "The specifier name is a ``dotted name'' that may resolve ... to
+ # ... a test method within a test case class"
+ #*****************************************************************
+ #Override the suiteClass attribute to ensure that the suiteClass
+ #attribute is used
+ def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self):
+ class SubTestSuite(unittest.TestSuite):
+ pass
+ m = types.ModuleType('m')
+ class MyTestCase(unittest.TestCase):
+ def test(self):
+ pass
+ m.testcase_1 = MyTestCase
+
+ loader = unittest.TestLoader()
+ loader.suiteClass=SubTestSuite
+ suite = loader.loadTestsFromName('testcase_1.test', m)
+ self.assertTrue(isinstance(suite, loader.suiteClass))
+
+ self.assertEqual(list(suite), [MyTestCase('test')])
+
+ # "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase or TestSuite instance"
#
# What happens if the callable returns something else?