包含文件
title: 包含文件
此示例演示如何包含文件,例如用作要导入的模块或要读取的文本文件,这些文件在工作目录中可用。
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',
)
CODE = """
from write_file import write_to_file
write_to_file()
"""
pyrunner.with_code(CODE).include_files("../differentdirectory/write_file.py").run()
然后工作目录中的“examplefile”文件将包含
â string of some kind
可执行规范
从 include-files.story storytests 自动生成的文档。