Skip to content
C

Mocked API Test

Mediumpython

Write a test using unittest.mock for a function that depends on an external API call, simulating a successful response without making a real network call.

Approach: getweatherdescription(weatherapicall) calls whatever function it's given and reads a "condition" field from the result. Instead of a real API, pass in a MagicMock configured to return a fixed dictionary — exactly what unittest.mock.patch would set up, just constructed directly here.

Input: One line: the weather condition to simulate (e.g. sunny).

Output: One line: Test passed: The weather is <condition>.

Input (stdin)

Output

Run your code to see output here...