diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py
index 7086d9a6a12..cb6366c7d5c 100644
--- a/Lib/test/test_docxmlrpc.py
+++ b/Lib/test/test_docxmlrpc.py
@@ -202,10 +202,12 @@ def test_annotations(self):
""" Test that annotations works as expected """
self.client.request("GET", "/")
response = self.client.getresponse()
+ docstring = (b'' if sys.flags.optimize >= 2 else
+ b'
Use function annotations.')
self.assertIn(
(b'- annotation'
- b'(x: int)
- Use function annotations.'
- b'
\n- '
+ b'(x: int)
' + docstring + b'
\n'
+ b'- '
b'method_annotation(x: bytes)
'),
response.read())
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index d04423777c9..75ae7f3a15d 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1126,7 +1126,8 @@ def g(obj):
"Simple test"
return "Test"
self.assertEqual(g.__name__, "g")
- self.assertEqual(g.__doc__, "Simple test")
+ if sys.flags.optimize < 2:
+ self.assertEqual(g.__doc__, "Simple test")
@unittest.skipUnless(decimal, 'requires _decimal')
@support.cpython_only
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 365f59230a4..520bf0e6083 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2529,7 +2529,8 @@ def test_details(self):
# Just a quick sanity check on the output
self.assertIn(module.__name__, output)
self.assertIn(module.__file__, output)
- self.assertIn(module.__cached__, output)
+ if not sys.flags.optimize:
+ self.assertIn(module.__cached__, output)
self.assertEqual(err, b'')
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index ee585e2c1c1..3d30d88f697 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -8,6 +8,7 @@
import doctest
import math
import random
+import sys
import types
import unittest
@@ -625,6 +626,8 @@ def test_check_all(self):
class DocTests(unittest.TestCase):
+ @unittest.skipIf(sys.flags.optimize >= 2,
+ "Docstrings are omitted with -OO and above")
def test_doc_tests(self):
failed, tried = doctest.testmod(statistics)
self.assertGreater(tried, 0)
diff --git a/Misc/NEWS b/Misc/NEWS
index 8e758cbf282..633ef5040ea 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -112,6 +112,9 @@ Library
Tests
-----
+- Issue #19535: Fixed test_docxmlrpc, test_functools, test_inspect, and
+ test_statistics when python is run with -OO.
+
- Issue #19926: Removed unneeded test_main from test_abstract_numbers.
Patch by Vajrasky Kok.