这是在python3中执行doctest作为 python3 -m doctest -v test_inventory.txt
的输出File "test_inventory.txt", line 10, in test_inventory.txt
Failed example:
from inventory import process
Expected nothing
Got:
{"project-abc": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dc-1": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dev": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "_meta": {"hostvars": {"node1.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}, "node2.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}}}}
这是我的doctest测试txt文件:-
>>> from inventory import process
>>> process()
'{"project-abc": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dc-1": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dev": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "_meta": {"hostvars": {"node1.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}, "node2.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}}}}'
我的测试调用的方法是:-
def process():
input_data = parser.generate_data()
groupwise_host_info = build_groupwise_host_info(input_data)
jsonOutput = parser.to_json(groupwise_host_info)
return jsonOutput
绝对可以返回json字符串。但是,库存导入过程中的测试步骤>>> -不应该期望它不返回任何与上述输出相反的结果吗?
我对第二个测试步骤的输出感到满意,它是:-
Trying:
process()
Expecting:
'{"project-abc": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dc-1": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "dev": {"hosts": ["node1.project-abc.dc-1.dev.com", "node2.project-abc.dc-1.dev.com"]}, "_meta": {"hostvars": {"node1.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}, "node2.project-abc.dc-1.dev.com": {"var1": 123, "var2": 456}}}}'
ok
任何人都可以澄清为什么“ from..import”测试步骤返回而不是什么都不返回吗?