Skip to content

Commit

Permalink
Fix #9868: ImportError on testing sphinx.util.inspect
Browse files Browse the repository at this point in the history
In some Linux distribution, ImportError is raised on testing
sphinx.util.inspect because _testcapi is not installed.
  • Loading branch information
tk0miya committed Nov 23, 2021
1 parent 538e281 commit c8f019a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/test_util_inspect.py
Expand Up @@ -16,7 +16,6 @@
import types
from inspect import Parameter

import _testcapi
import pytest

from sphinx.util import inspect
Expand Down Expand Up @@ -627,8 +626,6 @@ class Descriptor:
def __get__(self, obj, typ=None):
pass

testinstancemethod = _testcapi.instancemethod(str.__repr__)

assert inspect.isattributedescriptor(Base.prop) is True # property
assert inspect.isattributedescriptor(Base.meth) is False # method
assert inspect.isattributedescriptor(Base.staticmeth) is False # staticmethod
Expand All @@ -639,7 +636,16 @@ def __get__(self, obj, typ=None):
assert inspect.isattributedescriptor(dict.__dict__['fromkeys']) is False # ClassMethodDescriptorType # NOQA
assert inspect.isattributedescriptor(types.FrameType.f_locals) is True # GetSetDescriptorType # NOQA
assert inspect.isattributedescriptor(datetime.timedelta.days) is True # MemberDescriptorType # NOQA
assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # NOQA

try:
# _testcapi module cannot be importable in some distro
# refs: https://github.com/sphinx-doc/sphinx/issues/9868
import _testcapi

testinstancemethod = _testcapi.instancemethod(str.__repr__)
assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # NOQA
except ImportError:
pass


def test_isproperty(app):
Expand Down

0 comments on commit c8f019a

Please sign in to comment.