Skip to content

Commit 72225b5

Browse files
bpo-46111: Fix unittest tests in optimized mode (GH-30163)
(cherry picked from commit 95a922b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 212014d commit 72225b5

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎Lib/unittest/test/test_case.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ def testShortDescriptionWithMultiLineDocstring(self):
611611
'Tests shortDescription() for a method with a longer '
612612
'docstring.')
613613

614+
@unittest.skipIf(sys.flags.optimize >= 2,
615+
"Docstrings are omitted with -O2 and above")
614616
def testShortDescriptionWhitespaceTrimming(self):
615617
"""
616618
Tests shortDescription() whitespace is trimmed, so that the first

‎Lib/unittest/test/test_program.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def removeTest():
5858

5959
class FooBar(unittest.TestCase):
6060
def testPass(self):
61-
assert True
61+
pass
6262
def testFail(self):
63-
assert False
63+
raise AssertionError
6464

6565
class FooBarLoader(unittest.TestLoader):
6666
"""Test loader that returns a suite containing FooBar."""

‎Lib/unittest/test/testmock/testpatch.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,9 +1875,10 @@ def foo(x=0):
18751875
self.assertEqual(foo(), 1)
18761876
self.assertEqual(foo(), 0)
18771877

1878+
orig_doc = foo.__doc__
18781879
with patch.object(foo, '__doc__', "FUN"):
18791880
self.assertEqual(foo.__doc__, "FUN")
1880-
self.assertEqual(foo.__doc__, "TEST")
1881+
self.assertEqual(foo.__doc__, orig_doc)
18811882

18821883
with patch.object(foo, '__module__', "testpatch2"):
18831884
self.assertEqual(foo.__module__, "testpatch2")

0 commit comments

Comments
 (0)