0

I have taken up Python recently.
I'm trying to use unittest.Mock() for testing my code in PyCharm. But, PyCharm fails with the error:

requests = Mock()
TypeError: 'module' object is not callable

My program:

import requests
from unittest import Mock


requests = unittest.Mock()


def get_holidays():
    r = requests.get("http://localhost/holidays")
    if r.status_code == 200:
        return r.json()
    return None

Can anyone please help to identify where I am going wrong. Thanks

marie20
  • 723
  • 11
  • 30

1 Answers1

0

You have imported Mock from the unittest module, but you're trying to use it as unittest.Mock() instead of just Mock(). Try this instead:

import requests
from unittest.mock import Mock

requests = Mock()

def get_holidays():
    r = requests.get("http://localhost/holidays")
    if r.status_code == 200:
        return r.json()
    return None
AlefiyaAbbas
  • 235
  • 11