通过导入 test.support.script_helper 模块,你可以访问一些帮助函数来测试 Python 运行时:
test.support.script_helper
assert_python_ok(*args,**env_vars) 使用指定的参数执行 python 进程,并返回一个元组(返回代码、stdout、stderr)。
assert_python_ok(*args,**env_vars)
stdout
stderr
assert_python_failure(*args,**env_vars) 类似于 assert_python_ok(),但断言参数会执行失败。
assert_python_failure(*args,**env_vars)
assert_python_ok()
make_script(script_dir,script_basename,source) 使用 script_basename 和 source 在 script_dir 中生成一个脚本 ,然后返回脚本路径。其与 assert_python_ok() 或 assert_python_failure() 组合使用会更有效。
make_script(script_dir,script_basename,source)
script_basename
source
script_dir
assert_python_failure()
如果你想创建一个在模块未构建时会被跳过的测试,那么你可以使用 test.support.import_module() 工具函数。它将抛出一个 SkipTest 并向测试执行器发出跳过此测试包的信号。如下示例所示:
test.support.import_module()
SkipTest
import test.support _multiprocessing = test.support.import_module('_multiprocessing') # Your tests...
Last updated 2 years ago