Skip to content
Advertisement

Mock.patch returning MagicMock object causing AssertionError?

I have a function that I am trying to test in querySomething.py:

JavaScript

And the test file:

JavaScript

I am trying to mock the httpClient.get_request so that it gets the JSON file instead of reaching out to the API. We want to test an unauthorized response and a success response which explains the mock_response function. However, when I run the test, I get the following:

JavaScript

which is somewhat correct, but we need just the text, not the object. I read that I need to call the function, but when I try to call the function it throws a ModuleNotFound or NotAPackage error. What do I need to do to mock the httpClient.get_request and return the JSON string in the retrieveIssues function?

Advertisement

Answer

Updated, I was able to pull the JSON from the other file, and then was able to mock the return value as follows:

JavaScript

where load_json(“unauth”) pulls from the JSON response file.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement