我是 Python 中 unittest 库的新手。我在下面有一个示例代码,我想测试变量是否正确填充了值。首先我应该替换对配置阅读器的调用吗?我正在考虑提供一个配置文本,而不是从该位置读取以隔离。我怎样才能做到这一点?一些起点可能会有所帮助。
示例代码:
import sys
import os.path
from configparser import ConfigParser
templates=""
testfile=""
runbook=""
def init():
global templates
global testfile
global runbook
if len(sys.argv) > 1:
currPath = sys.argv[1]
else: currPath = r"Directory path"
conf = os.path.join(currPath,"temp.properties")
config = ConfigParser()
config.read(conf)
templates = os.path.join(currPath, config.get("setting", "Templates"))
testfile = os.path.join(currPath, config.get("setting", "Testfile"))
runbook = os.path.join(currPath, config.get("setting", "Runbook"))
我的 temp.properties 文件
[setting]
Templates=temp\Templates.xml
Testfile=reports\TestCases.xml
Runbook=reports\Runbook.xml