0

I have a method that calls the set_status api of the webapp2.Response class:

class RequestHandler(webapp2.RequestHandler):
  some_method(self):
    self.response.set_status(200)

I am writing tests for some_method() and mocking the set_status method:

class BaseTest(unittest.TestCase):
  def setUp(self):
    # Set up stuff.

  @mock.patch.object(Response, 'set_status')
  def testSomeMethod()
    some_method()

However when I run the test I get:

'NoneType' object has no attribute 'set_status'

Why is the call to set_status() not getting mocked?

Shan
  • 1,138
  • 17
  • 32
  • Please write your test code. Like it is there are no chances to write an answer. The issue is in `patch` call but without knowing the context we should guess too much. Just one shot: try to use `mock.patch("webapp2.Response.set_satus")` instead. – Michele d'Amico Feb 15 '16 at 10:13
  • @Micheled'Amico Added the test code. Please take a look. Using mock.patch("webapp2.Response.set_satus") didn't help. – Shan Feb 15 '16 at 13:13
  • Please and also how you import `Response` in test module. It will be useful to have the exact stack trace error. Just a question: did you have the same error by use `mock.patch("webapp2.Response.set_satus")`? – Michele d'Amico Feb 15 '16 at 13:57
  • @Micheled'Amico `from webapp2 import Response`. I got the same error when using `mock.patch("webapp2.Response.set_satus")`. Sorry I won't be able to share the stack trace, it may reveal some confidential company code. – Shan Feb 15 '16 at 14:03
  • Ok, I'm quite sure that the `patch` doesn't mater in this context: maybe `self.response` is `None` in `some_method()` – Michele d'Amico Feb 15 '16 at 15:38
  • @Michele d'Amico Yep, that was the problem. It's now resolved. Thank you !! – Shan Feb 15 '16 at 16:13

0 Answers0