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

Function validate_namespace_package

testing/test_pathlib.py:1738–1756  ·  view source on GitHub ↗

Validate that a Python namespace package is set up correctly. In a sub interpreter, add 'paths' to sys.path and attempt to import the given modules. In this module many tests configure a set of files as a namespace package, this function is used as sanity check that our files are

(
    pytester: Pytester, paths: Sequence[Path], modules: Sequence[str]
)

Source from the content-addressed store, hash-verified

1736
1737
1738def validate_namespace_package(
1739 pytester: Pytester, paths: Sequence[Path], modules: Sequence[str]
1740) -> RunResult:
1741 """
1742 Validate that a Python namespace package is set up correctly.
1743
1744 In a sub interpreter, add 'paths' to sys.path and attempt to import the given modules.
1745
1746 In this module many tests configure a set of files as a namespace package, this function
1747 is used as sanity check that our files are configured correctly from the point of view of Python.
1748 """
1749 lines = [
1750 "import sys",
1751 # Configure sys.path.
1752 *[f"sys.path.append(r{str(x)!r})" for x in paths],
1753 # Imports.
1754 *[f"import {x}" for x in modules],
1755 ]
1756 return pytester.runpython_c("\n".join(lines))

Calls 2

joinMethod · 0.80
runpython_cMethod · 0.45

Tested by

no test coverage detected