]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46111: Fix unittest tests in optimized mode (GH-30163)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 17 Dec 2021 09:10:55 +0000 (11:10 +0200)
committerGitHub <noreply@github.com>
Fri, 17 Dec 2021 09:10:55 +0000 (11:10 +0200)
Lib/unittest/test/test_case.py
Lib/unittest/test/test_program.py
Lib/unittest/test/testmock/testpatch.py

index ee4c0b354f72b79da743944923873f043608d0e5..067ec8d458679f265bebe2f1230c308b441b296d 100644 (file)
@@ -631,6 +631,8 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
                  'Tests shortDescription() for a method with a longer '
                  'docstring.')
 
+    @unittest.skipIf(sys.flags.optimize >= 2,
+                     "Docstrings are omitted with -O2 and above")
     def testShortDescriptionWhitespaceTrimming(self):
         """
             Tests shortDescription() whitespace is trimmed, so that the first
index cc02b227e1da8ae58b79bebfc737ee42cfb41fd4..2bf7dd72ed21cd8c73eb368a43cc44a87f25f735 100644 (file)
@@ -58,9 +58,9 @@ class Test_TestProgram(unittest.TestCase):
 
     class FooBar(unittest.TestCase):
         def testPass(self):
-            assert True
+            pass
         def testFail(self):
-            assert False
+            raise AssertionError
 
     class FooBarLoader(unittest.TestLoader):
         """Test loader that returns a suite containing FooBar."""
index d8c1515f8346c33894e10d1591bd510215a5bbba..233a5afffaed4a5f6fbb65a398b1b40ce19b4a9f 100644 (file)
@@ -1875,9 +1875,10 @@ class PatchTest(unittest.TestCase):
             self.assertEqual(foo(), 1)
         self.assertEqual(foo(), 0)
 
+        orig_doc = foo.__doc__
         with patch.object(foo, '__doc__', "FUN"):
             self.assertEqual(foo.__doc__, "FUN")
-        self.assertEqual(foo.__doc__, "TEST")
+        self.assertEqual(foo.__doc__, orig_doc)
 
         with patch.object(foo, '__module__', "testpatch2"):
             self.assertEqual(foo.__module__, "testpatch2")