MCPcopy
hub / github.com/pytest-dev/pytest / spec_matches_module_path

Function spec_matches_module_path

src/_pytest/pathlib.py:729–745  ·  view source on GitHub ↗

Return true if the given ModuleSpec can be used to import the given module path.

(module_spec: ModuleSpec | None, module_path: Path)

Source from the content-addressed store, hash-verified

727
728
729def spec_matches_module_path(module_spec: ModuleSpec | None, module_path: Path) -> bool:
730 """Return true if the given ModuleSpec can be used to import the given module path."""
731 if module_spec is None:
732 return False
733
734 if module_spec.origin:
735 return Path(module_spec.origin) == module_path
736
737 # Compare the path with the `module_spec.submodule_Search_Locations` in case
738 # the module is part of a namespace package.
739 # https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec.submodule_search_locations
740 if module_spec.submodule_search_locations: # can be None.
741 for path in module_spec.submodule_search_locations:
742 if Path(path) == module_path:
743 return True
744
745 return False
746
747
748# Implement a special _is_same function on Windows which returns True if the two filenames

Callers 3

is_importableFunction · 0.85

Calls

no outgoing calls

Tested by 1