跳至内容

变量


标题: 使用模块

此示例演示如何将包含字符串的变量馈送到正在运行的代码中。

from hitchrunpy import ExamplePythonCode
from ensure import Ensure
import hitchbuildpy
import hitchbuild

BUILD_DIR = "/path/to/build_dir/.."

virtualenv = hitchbuildpy.VirtualenvBuild(
    "/path/to/build_dir/../py3.7",
    base_python=hitchbuildpy.PyenvBuild(
        '/path/to/share_dir/../pyenv3.7',
        "3.7",
    ),
)

virtualenv.verify()

pyrunner = ExamplePythonCode(
    virtualenv.bin.python,
    '/path/to/working_dir',
)
some_string = u"â string of some kind"

pyrunner.with_code((
    "from write_to_file import write_text\n"
    "write_text()"
)).with_modules(f"{BUILD_DIR}/state/write_to_file.py").run()

然后工作目录中的“examplefile”文件将包含

â string of some kind

可执行规范

with-modules.story storytests 自动生成的文档。