CS FundamentalsVery hardProduct-company placement · Python interview
Module report.py does `from pricing import get_rate` and calls get_rate() inside build(). A unit test for build() uses unittest.mock.patch('pricing.get_rate'), but build() still calls the real function. Why?
- A. patch works only on classes
- B. The mock must be created before pricing is imported anywhere
- C. patch never works on functions
- D. report already holds its own reference named report.get_rate, so the patch target must be 'report.get_rate' - patch where the name is looked up, not where it is defined
Correct answer: D. report already holds its own reference named report.get_rate, so the patch target must be 'report.get_rate' - patch where the name is looked up, not where it is defined
from-import copies the reference into report's namespace. Replacing pricing.get_rate afterwards does not change report.get_rate. If report had used import pricing and pricing.get_rate(), patching pricing.get_rate would work.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A faulty merge M of feature into main was undone with git revert -m 1 M. The feature team later fixes the bug with a new commit on feature…
- You run git stash pop and it reports a merge conflict in f.txt. What happens to the stash entry?
- During git rebase -i, what is the difference between marking a commit 'squash' and marking it 'fixup'?
- On main you need the version of config.yml that exists on branch release, without merging anything else. Which command does this, and what…
- A file was renamed from util.js to helpers.js three months ago. git log helpers.js shows only the commits since the rename. Which command…
- Branches deleted on the remote still appear in git branch -r on a developer's machine. Which command removes these stale remote-tracking…