]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescripti...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 3 Feb 2020 07:25:17 +0000 (23:25 -0800)
committerGitHub <noreply@github.com>
Mon, 3 Feb 2020 07:25:17 +0000 (07:25 +0000)
(cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759)

Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
Lib/unittest/case.py
Lib/unittest/test/test_case.py
Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst [new file with mode: 0644]

index 811f5df23dd14a92b5cd21623b2d4e65da05a3c9..24af29057646a0b0a4e35148a7aecef1141a72a3 100644 (file)
@@ -493,7 +493,7 @@ class TestCase(object):
         the specified test method's docstring.
         """
         doc = self._testMethodDoc
-        return doc and doc.split("\n")[0].strip() or None
+        return doc.strip().split("\n")[0].strip() if doc else None
 
 
     def id(self):
index 6d58201ea8143a039d5cb0d9ca05d5400a78c0aa..4fac8d59745289a6b238042e53d9c29c66d77eb4 100644 (file)
@@ -610,6 +610,15 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
                  'Tests shortDescription() for a method with a longer '
                  'docstring.')
 
+    def testShortDescriptionWhitespaceTrimming(self):
+        """
+            Tests shortDescription() whitespace is trimmed, so that the first
+            line of nonwhite-space text becomes the docstring.
+        """
+        self.assertEqual(
+            self.shortDescription(),
+            'Tests shortDescription() whitespace is trimmed, so that the first')
+
     def testAddTypeEqualityFunc(self):
         class SadSnake(object):
             """Dummy class for test_addTypeEqualityFunc."""
diff --git a/Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst b/Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst
new file mode 100644 (file)
index 0000000..55fed51
--- /dev/null
@@ -0,0 +1,2 @@
+Striped whitespace from docstring before returning it from
+:func:`unittest.case.shortDescription`.