用于打开和阅读网址的单元测试

时间:2016-06-11 10:23:13

标签: python mocking urllib

我正在编写单元测试,但我无法理解如何编写单元测试来阅读网址。

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并阅读?

0 个答案:

没有答案