Skip to content

Commit 95a922b

Browse files
bpo-46111: Fix unittest tests in optimized mode (GH-30163)
1 parent 69ef1b5 commit 95a922b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Lib/unittest/test/test_case.py

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

634+
@unittest.skipIf(sys.flags.optimize >= 2,
635+
"Docstrings are omitted with -O2 and above")
634636
def testShortDescriptionWhitespaceTrimming(self):
635637
"""
636638
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)