Skip to content

Commit b12cb6a

Browse files
Issue #19535: Fixed test_docxmlrpc, test_functools, test_inspect, and
test_statistics when python is run with -OO.
2 parents ca616a2 + 3e60a9d commit b12cb6a

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lib/test/test_docxmlrpc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ def test_annotations(self):
202202
""" Test that annotations works as expected """
203203
self.client.request("GET", "/")
204204
response = self.client.getresponse()
205+
docstring = (b'' if sys.flags.optimize >= 2 else
206+
b'<dd><tt>Use&nbsp;function&nbsp;annotations.</tt></dd>')
205207
self.assertIn(
206208
(b'<dl><dt><a name="-annotation"><strong>annotation</strong></a>'
207-
b'(x: int)</dt><dd><tt>Use&nbsp;function&nbsp;annotations.</tt>'
208-
b'</dd></dl>\n<dl><dt><a name="-method_annotation"><strong>'
209+
b'(x: int)</dt>' + docstring + b'</dl>\n'
210+
b'<dl><dt><a name="-method_annotation"><strong>'
209211
b'method_annotation</strong></a>(x: bytes)</dt></dl>'),
210212
response.read())
211213

Lib/test/test_functools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,8 @@ def g(obj):
11261126
"Simple test"
11271127
return "Test"
11281128
self.assertEqual(g.__name__, "g")
1129-
self.assertEqual(g.__doc__, "Simple test")
1129+
if sys.flags.optimize < 2:
1130+
self.assertEqual(g.__doc__, "Simple test")
11301131

11311132
@unittest.skipUnless(decimal, 'requires _decimal')
11321133
@support.cpython_only

Lib/test/test_inspect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,8 @@ def test_details(self):
25292529
# Just a quick sanity check on the output
25302530
self.assertIn(module.__name__, output)
25312531
self.assertIn(module.__file__, output)
2532-
self.assertIn(module.__cached__, output)
2532+
if not sys.flags.optimize:
2533+
self.assertIn(module.__cached__, output)
25332534
self.assertEqual(err, b'')
25342535

25352536

Lib/test/test_statistics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import doctest
99
import math
1010
import random
11+
import sys
1112
import types
1213
import unittest
1314

@@ -625,6 +626,8 @@ def test_check_all(self):
625626

626627

627628
class DocTests(unittest.TestCase):
629+
@unittest.skipIf(sys.flags.optimize >= 2,
630+
"Docstrings are omitted with -OO and above")
628631
def test_doc_tests(self):
629632
failed, tried = doctest.testmod(statistics)
630633
self.assertGreater(tried, 0)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ Library
112112
Tests
113113
-----
114114

115+
- Issue #19535: Fixed test_docxmlrpc, test_functools, test_inspect, and
116+
test_statistics when python is run with -OO.
117+
115118
- Issue #19926: Removed unneeded test_main from test_abstract_numbers.
116119
Patch by Vajrasky Kok.
117120

0 commit comments

Comments
 (0)