我正在编写单元测试,但我无法理解如何编写单元测试来阅读网址。
def testing():
main_ip = "localhost"
another_url = "http://localhost:8086/test"
try:
response = urllib2.urlopen(another_url)
body = response.read()
if body:
main_ip = body.split(':')[0]
except urllib2.URLError as urlerr:
pass
return main_ip
我不明白如何为urlopen模拟或编写unittest并阅读?