]> 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 08:20:41 +0000 (00:20 -0800)
committerGitHub <noreply@github.com>
Mon, 3 Feb 2020 08:20:41 +0000 (08:20 +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 b639c64d02a7aac4c2d292c194a2df71f4858414..e5734b6b7a298bd60338d5e599047d1de3cf00b1 100644 (file)
@@ -529,7 +529,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 c2401c39b917e30f591b19669d8c762dba97ac7d..f855c4dc00b316ee90b0d750e5f2a614fae6f5d4 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`.