Skip to content

Commit e4c915d

Browse files
committed
fix test
1 parent c1b2711 commit e4c915d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_extensions/test_ext_autodoc_automodule.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
source file translated by test_build.
55
"""
66

7+
import inspect
78
import sys
9+
import typing
810

911
import pytest
1012

@@ -185,8 +187,22 @@ def test_automodule_inherited_members(app):
185187
'sphinx.missing_module4']})
186188
@pytest.mark.usefixtures("rollback_sysmodules")
187189
def test_subclass_of_mocked_object(app):
190+
from sphinx.ext.autodoc.mock import _MockObject
188191
sys.modules.pop('target', None) # unload target module to clear the module cache
189192

193+
options = {'members': None}
194+
actual = do_autodoc(app, 'module', 'target.need_mocks', options)
195+
# ``typing.Any`` is not available at runtime on ``_MockObject.__new__``
196+
assert '.. py:class:: Inherited(*args: Any, **kwargs: Any)' in actual
197+
198+
# make ``typing.Any`` available at runtime on ``_MockObject.__new__``
199+
sig = inspect.signature(_MockObject.__new__)
200+
parameters = sig.parameters.copy()
201+
for name in ('args', 'kwargs'):
202+
parameters[name] = parameters[name].replace(annotation=typing.Any)
203+
sig = sig.replace(parameters=tuple(parameters.values()))
204+
_MockObject.__new__.__signature__ = sig # type: ignore[attr-defined]
205+
190206
options = {'members': None}
191207
actual = do_autodoc(app, 'module', 'target.need_mocks', options)
192208
assert '.. py:class:: Inherited(*args: ~typing.Any, **kwargs: ~typing.Any)' in actual

0 commit comments

Comments
 (0)