Skip to content

Commit 7d4ca9c

Browse files
authored
Fix autodoc tests for Python 3.11 and later (#11793)
Since Python 3.11.7, 3.12.0 and 3.13.0a2, "list of weak references to the object (if defined)" was changed to "list of weak references to the object". Add a version check to decide which text to assert.
1 parent 6ee194f commit 7d4ca9c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/test_ext_autodoc_configs.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,14 @@ def test_autodoc_typehints_format_fully_qualified_for_newtype_alias(app):
15841584

15851585
@pytest.mark.sphinx('html', testroot='ext-autodoc')
15861586
def test_autodoc_default_options(app):
1587+
if (
1588+
(3, 11, 7) <= sys.version_info < (3, 12)
1589+
or sys.version_info >= (3, 12, 1)
1590+
):
1591+
list_of_weak_references = " list of weak references to the object"
1592+
else:
1593+
list_of_weak_references = " list of weak references to the object (if defined)"
1594+
15871595
# no settings
15881596
actual = do_autodoc(app, 'class', 'target.enums.EnumCls')
15891597
assert ' .. py:attribute:: EnumCls.val1' not in actual
@@ -1627,7 +1635,7 @@ def test_autodoc_default_options(app):
16271635
assert ' Iterate squares of each value.' in actual
16281636
if not IS_PYPY:
16291637
assert ' .. py:attribute:: CustomIter.__weakref__' in actual
1630-
assert ' list of weak references to the object (if defined)' in actual
1638+
assert list_of_weak_references in actual
16311639

16321640
# :exclude-members: None - has no effect. Unlike :members:,
16331641
# :special-members:, etc. where None == "include all", here None means
@@ -1651,13 +1659,21 @@ def test_autodoc_default_options(app):
16511659
assert ' Iterate squares of each value.' in actual
16521660
if not IS_PYPY:
16531661
assert ' .. py:attribute:: CustomIter.__weakref__' in actual
1654-
assert ' list of weak references to the object (if defined)' in actual
1662+
assert list_of_weak_references in actual
16551663
assert ' .. py:method:: CustomIter.snafucate()' in actual
16561664
assert ' Makes this snafucated.' in actual
16571665

16581666

16591667
@pytest.mark.sphinx('html', testroot='ext-autodoc')
16601668
def test_autodoc_default_options_with_values(app):
1669+
if (
1670+
(3, 11, 7) <= sys.version_info < (3, 12)
1671+
or sys.version_info >= (3, 12, 1)
1672+
):
1673+
list_of_weak_references = " list of weak references to the object"
1674+
else:
1675+
list_of_weak_references = " list of weak references to the object (if defined)"
1676+
16611677
# with :members:
16621678
app.config.autodoc_default_options = {'members': 'val1,val2'}
16631679
actual = do_autodoc(app, 'class', 'target.enums.EnumCls')
@@ -1698,7 +1714,7 @@ def test_autodoc_default_options_with_values(app):
16981714
assert ' Iterate squares of each value.' in actual
16991715
if not IS_PYPY:
17001716
assert ' .. py:attribute:: CustomIter.__weakref__' not in actual
1701-
assert ' list of weak references to the object (if defined)' not in actual
1717+
assert list_of_weak_references not in actual
17021718

17031719
# with :exclude-members:
17041720
app.config.autodoc_default_options = {
@@ -1722,6 +1738,6 @@ def test_autodoc_default_options_with_values(app):
17221738
assert ' Iterate squares of each value.' in actual
17231739
if not IS_PYPY:
17241740
assert ' .. py:attribute:: CustomIter.__weakref__' not in actual
1725-
assert ' list of weak references to the object (if defined)' not in actual
1741+
assert list_of_weak_references not in actual
17261742
assert ' .. py:method:: CustomIter.snafucate()' not in actual
17271743
assert ' Makes this snafucated.' not in actual

0 commit comments

Comments
 (0)