A. The assertion expects the original value, but mocking changed it to 20
B. The monkeypatch syntax is incorrect
C. The function get_value is not defined
D. The test is missing a return statement
Solution
Step 1: Analyze the monkeypatch effect
The monkeypatch replaces get_value to return 20 instead of 10.
Step 2: Check the assertion
The assertion expects 10, but the mocked function returns 20, causing failure.
Final Answer:
The assertion expects the original value, but mocking changed it to 20 -> Option A
Quick Check:
Mock changes output, assertion expects old value [OK]
Hint: Assertion fails if expected value ignores mocking effect [OK]
Common Mistakes:
Thinking monkeypatch syntax is wrong
Assuming function is undefined
Believing test needs a return statement
5. You have a function send_email() that sends real emails. You want to test notify_user() which calls send_email()</>. How does mocking send_email() help isolate notify_user() in pytest?
hard
A. It disables notify_user completely
B. It makes notify_user send multiple emails automatically
C. It connects notify_user to the real email server faster
D. It prevents real emails from sending and lets you test notify_user's logic only
Solution
Step 1: Identify the problem with real send_email
Calling real send_email() during tests can send unwanted emails and slow tests.
Step 2: Understand mocking benefit
Mocking send_email() replaces it with a fake that does nothing or simulates success, isolating notify_user() logic.
Final Answer:
It prevents real emails from sending and lets you test notify_user's logic only -> Option D
Quick Check:
Mocking avoids side effects, isolates tested code [OK]
Hint: Mock side-effect functions to isolate main logic in tests [OK]
Common Mistakes:
Thinking mocking triggers real side effects
Assuming mocking disables the tested function
Believing mocking speeds up real connections
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.