Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3198275

Browse files
committed
Topical change: use 'startswith()' to identify test methods with a
given prefix rather than comparing a slice.
1 parent 09fad27 commit 3198275

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def testMultiply(self):
4646

4747
__author__ = "Steve Purcell"
4848
__email__ = "stephen_purcell at yahoo dot com"
49-
__version__ = "#Revision: 1.56 $"[11:-2]
49+
__version__ = "#Revision: 1.57 $"[11:-2]
5050

5151
import time
5252
import sys
@@ -540,7 +540,7 @@ def getTestCaseNames(self, testCaseClass):
540540
"""Return a sorted sequence of method names found within testCaseClass
541541
"""
542542
def isTestMethod(attrname, testCaseClass=testCaseClass, prefix=self.testMethodPrefix):
543-
return attrname[:len(prefix)] == prefix and callable(getattr(testCaseClass, attrname))
543+
return attrname.startswith(prefix) and callable(getattr(testCaseClass, attrname))
544544
testFnNames = filter(isTestMethod, dir(testCaseClass))
545545
for baseclass in testCaseClass.__bases__:
546546
for testFnName in self.getTestCaseNames(baseclass):

0 commit comments

Comments
 (0)