diff options
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r-- | Lib/unittest.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index adbbe8a..742871b 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -504,6 +504,15 @@ class FunctionTestCase(TestCase): # Locating and loading tests ############################################################################## +def CmpToKey(mycmp): + 'Convert a cmp= function into a key= function' + class K(object): + def __init__(self, obj, *args): + self.obj = obj + def __lt__(self, other): + return mycmp(self.obj, other.obj) == -1 + return K + class TestLoader: """This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite @@ -598,7 +607,7 @@ class TestLoader: and hasattr(getattr(testCaseClass, attrname), '__call__') testFnNames = list(filter(isTestMethod, dir(testCaseClass))) if self.sortTestMethodsUsing: - testFnNames.sort(self.sortTestMethodsUsing) + testFnNames.sort(key=CmpToKey(self.sortTestMethodsUsing)) return testFnNames |