Skip to content

Commit

Permalink
BUG: collect methods from private superclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
ev-br committed Dec 15, 2024
1 parent 5113870 commit fe93a74
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scipy_doctest/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def find_doctests(module, strategy=None,
t = _finder.find(item, name, globs=globs, extraglobs=extraglobs)
else:
t = finder.find(item, full_name, globs=globs, extraglobs=extraglobs)

if hasattr(item, '__mro__'):
# is a class, inspect superclasses
# cf https://github.com/scipy/scipy_doctest/issues/177
# item.__mro__ starts with itself, ends with `object`
for item_ in item.__mro__[1:-1]:
t_ = finder.find(item_, full_name, globs=globs, extraglobs=extraglobs)
t += t_
tests += t

# If the skiplist contains methods of objects, their doctests may have been
Expand Down
22 changes: 22 additions & 0 deletions scipy_doctest/tests/finder_cases_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Private method in subclasses
"""

__all__ = ["Klass"]

class _PrivateKlass:
def private_method(self):
"""
>>> 2 / 3
0.667
"""
pass


class Klass(_PrivateKlass):
def public_method(self):
"""
>>> 3 / 4
0.74
"""
pass
12 changes: 12 additions & 0 deletions scipy_doctest/tests/test_finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from . import finder_cases
from . import finder_cases_2
from ..util import get_all_list, get_public_objects
from ..impl import DTFinder, DTConfig
from ..frontend import find_doctests
Expand Down Expand Up @@ -168,3 +169,14 @@ def test_dtfinder_config():
config = DTConfig()
finder = DTFinder(config=config)
assert finder.config is config


@pytest.mark.parametrize('strategy', [None, 'api'])
def test_private_superclasses(strategy):
# Test that methods from inherited private superclasses get collected
tests = find_doctests(finder_cases_2, strategy=strategy)

names = set(test.name.split('.')[-1] for test in tests)
assert len(tests) == 3
assert names == {'finder_cases_2', 'public_method', 'private_method'}

0 comments on commit fe93a74

Please sign in to comment.