From 5a69b4d7c3c8ff0c9f691ca8942b65ca88427ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Dantas?= Date: Wed, 1 Mar 2017 13:54:33 -0300 Subject: [PATCH] Changed case.shortDescription to return empty string instead of None --- Lib/unittest/case.py | 4 ++-- Lib/unittest/test/test_case.py | 2 +- Lib/unittest/test/test_functiontestcase.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index b523f73ff22784..6ee77c555896d2 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -466,7 +466,7 @@ def shortDescription(self): the specified test method's docstring. """ doc = self._testMethodDoc - return doc and doc.split("\n")[0].strip() or None + return doc and doc.split("\n")[0].strip() or '' def id(self): @@ -1381,7 +1381,7 @@ def shortDescription(self): if self._description is not None: return self._description doc = self._testFunc.__doc__ - return doc and doc.split("\n")[0].strip() or None + return doc and doc.split("\n")[0].strip() or '' class _SubTest(TestCase): diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 8f752b8ae0d0e2..c3e837583bd3d9 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -572,7 +572,7 @@ def run(self, result): def testShortDescriptionWithoutDocstring(self): - self.assertIsNone(self.shortDescription()) + self.assertFalse(self.shortDescription()) @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") diff --git a/Lib/unittest/test/test_functiontestcase.py b/Lib/unittest/test/test_functiontestcase.py index c5f2bcbe741b61..e174cadab92eae 100644 --- a/Lib/unittest/test/test_functiontestcase.py +++ b/Lib/unittest/test/test_functiontestcase.py @@ -128,11 +128,12 @@ def test_id(self): # "Returns a one-line description of the test, or None if no description # has been provided. The default implementation of this method returns - # the first line of the test method's docstring, if available, or None." + # the first line of the test method's docstring, if available, or empty + # string." def test_shortDescription__no_docstring(self): test = unittest.FunctionTestCase(lambda: None) - self.assertEqual(test.shortDescription(), None) + self.assertEqual(test.shortDescription(), '') # "Returns a one-line description of the test, or None if no description # has been provided. The default implementation of this method returns