diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index 9261c69dd4b..66cedee9b75 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -289,7 +289,7 @@ def skipfile(filename, tested_optional_tags=False, *, if log: log(f"Skipping '{filename}' because it is created by the jupyter-sphinx extension for internal use and should not be tested") return True - if if_installed and ext in ('.py', '.pyx', '.pxd'): + if if_installed: module_name = get_basename(filename) try: if not importlib.util.find_spec(module_name): # tries to import the containing package diff --git a/src/sage/doctest/sources.py b/src/sage/doctest/sources.py index d5dc83f0e1a..5064496052b 100644 --- a/src/sage/doctest/sources.py +++ b/src/sage/doctest/sources.py @@ -84,8 +84,10 @@ def get_basename(path): sage: from sage.doctest.sources import get_basename sage: from sage.env import SAGE_SRC sage: import os - sage: get_basename(os.path.join(SAGE_SRC,'sage','doctest','sources.py')) + sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'doctest', 'sources.py')) 'sage.doctest.sources' + sage: get_basename(os.path.join(SAGE_SRC, 'sage', 'structure', 'element.pxd')) + 'sage.structure.element.pxd' """ if path is None: return None @@ -111,10 +113,14 @@ def get_basename(path): # it goes. while is_package_or_sage_namespace_package_dir(root): root = os.path.dirname(root) - fully_qualified_path = os.path.splitext(path[len(root) + 1:])[0] + fully_qualified_path, ext = os.path.splitext(path[len(root) + 1:]) if os.path.split(path)[1] == '__init__.py': fully_qualified_path = fully_qualified_path[:-9] - return fully_qualified_path.replace(os.path.sep, '.') + basename = fully_qualified_path.replace(os.path.sep, '.') + if ext in ['.pxd', '.pxi']: + # disambiguate from .pyx with the same basename + basename += ext + return basename class DocTestSource():