diff --git a/scipy_doctest/impl.py b/scipy_doctest/impl.py index 8f87bed..1947f58 100644 --- a/scipy_doctest/impl.py +++ b/scipy_doctest/impl.py @@ -1,5 +1,6 @@ import re import warnings +import inspect import doctest from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL from itertools import zip_longest @@ -538,6 +539,19 @@ def find(self, obj, name=None, module=None, globs=None, extraglobs=None): # XXX: does this make similar checks in testmod/testfile duplicate? if module not in self.config.skiplist: tests = super().find(obj, name, module, globs, extraglobs) + + if inspect.isclass(obj): + descriptors = [ + (name_, method) + for name_, method in inspect.getmembers(obj) + if inspect.isdatadescriptor(method) + ] + + for name_, method in descriptors: + tests += super().find( + method, f'{name}.{name_}', module, globs, extraglobs + ) + return tests diff --git a/scipy_doctest/tests/test_finder.py b/scipy_doctest/tests/test_finder.py index 5453e38..3ab679a 100644 --- a/scipy_doctest/tests/test_finder.py +++ b/scipy_doctest/tests/test_finder.py @@ -1,10 +1,13 @@ import pytest +import numpy as np + from . import finder_cases from ..util import get_all_list, get_public_objects from ..impl import DTFinder, DTConfig from ..frontend import find_doctests + def test_get_all_list(): items, depr, other = get_all_list(finder_cases) assert sorted(items) == ['Klass', 'func'] @@ -168,3 +171,11 @@ def test_dtfinder_config(): config = DTConfig() finder = DTFinder(config=config) assert finder.config is config + + +@pytest.mark.skipif(np.__version__ < '2', reason="XXX check if works on numpy 1.x") +def test_descriptors_get_collected(): + tests = find_doctests(np, strategy=[np.dtype]) + names = [test.name for test in tests] + assert 'numpy.dtype.kind' in names # was previously missing +