MCPcopy Index your code
hub / github.com/github/spec-kit / test_package_relative_import

Method test_package_relative_import

tests/test_workflows.py:5198–5234  ·  view source on GitHub ↗

Steps can use relative imports to access sibling modules.

(self, project_dir)

Source from the content-addressed store, hash-verified

5196 assert module_name in sys.modules
5197
5198 def test_package_relative_import(self, project_dir):
5199 """Steps can use relative imports to access sibling modules."""
5200 import hashlib
5201 import sys
5202 from specify_cli.workflows import load_custom_steps, STEP_REGISTRY
5203
5204 step_dir = project_dir / ".specify" / "workflows" / "steps" / "pkg-step"
5205 step_dir.mkdir(parents=True)
5206 (step_dir / "step.yml").write_text(
5207 "step:\n type_key: pkg-step\n name: Package Step\n",
5208 encoding="utf-8",
5209 )
5210 # Helper module that the step will import relatively
5211 (step_dir / "helpers.py").write_text(
5212 "HELPER_VALUE = 'hello'\n", encoding="utf-8"
5213 )
5214 init_py = """
5215from specify_cli.workflows.base import StepBase, StepResult
5216from .helpers import HELPER_VALUE
5217
5218class PkgStep(StepBase):
5219 type_key = "pkg-step"
5220 helper = HELPER_VALUE
5221
5222 def execute(self, config, context):
5223 return StepResult()
5224"""
5225 (step_dir / "__init__.py").write_text(init_py, encoding="utf-8")
5226
5227 loaded = load_custom_steps(project_dir)
5228 assert "pkg-step" in loaded
5229 assert "pkg-step" in STEP_REGISTRY
5230 # Verify the relative import actually resolved; module name includes hash suffix.
5231 key_hash = hashlib.sha256(b"pkg-step").hexdigest()[:8]
5232 module_name = f"_speckit_custom_step_pkg_step_{key_hash}"
5233 assert module_name in sys.modules
5234 assert sys.modules[module_name].PkgStep.helper == "hello"
5235
5236 def test_module_name_collision_resistance(self, project_dir):
5237 """'a-b' and 'a_b' produce different module names despite the same sanitized form."""

Callers

nothing calls this directly

Calls 1

load_custom_stepsFunction · 0.90

Tested by

no test coverage detected