]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescripti...
authorSteve Cirelli <scirelli+git@gmail.com>
Mon, 3 Feb 2020 07:06:50 +0000 (02:06 -0500)
committerGitHub <noreply@github.com>
Mon, 3 Feb 2020 07:06:50 +0000 (07:06 +0000)
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 fa64a6ea2378c0b0da1863dd1a2ce7a393f7ca31..5e5d535dc693870f5437336d217a2c34e4b60e5e 100644 (file)
@@ -512,7 +512,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`.