0

I am writting unittests and I am not able to understand how can I write unittest for reading a url.

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

I do not understand how can I mock or write unittest for urlopen and read?

sam
  • 18,509
  • 24
  • 83
  • 116
  • No. Its very simple and basic example & diff from that question. Can you explain me how to work on this? – sam Jun 11 '16 at 14:09
  • The duplicate seems pertinent to me. If you disagree, please [edit] your question to clarify why the answers in the duplicate are not suitable for your scenario. – tripleee Jun 11 '16 at 14:55

0 Answers0