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

Function test_is_importable

testing/test_pathlib.py:1699–1722  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

1697
1698
1699def test_is_importable(pytester: Pytester) -> None:
1700 pytester.syspathinsert()
1701
1702 path = pytester.path / "bar/foo.py"
1703 path.parent.mkdir()
1704 path.touch()
1705 assert is_importable("bar.foo", path) is True
1706
1707 # Ensure that the module that can be imported points to the path we expect.
1708 path = pytester.path / "some/other/path/bar/foo.py"
1709 path.mkdir(parents=True, exist_ok=True)
1710 assert is_importable("bar.foo", path) is False
1711
1712 # Paths containing "." cannot be imported.
1713 path = pytester.path / "bar.x/__init__.py"
1714 path.parent.mkdir()
1715 path.touch()
1716 assert is_importable("bar.x", path) is False
1717
1718 # Pass starting with "." denote relative imports and cannot be checked using is_importable.
1719 path = pytester.path / ".bar.x/__init__.py"
1720 path.parent.mkdir()
1721 path.touch()
1722 assert is_importable(".bar.x", path) is False
1723
1724
1725def test_compute_module_name(tmp_path: Path) -> None:

Callers

nothing calls this directly

Calls 3

is_importableFunction · 0.90
syspathinsertMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected