All quizzes
Free quiz · 20 questions in the bank

Mock quiz

Test your Mock knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.

Question 1/5Score 0

How does `unittest.mock.patch` handle patching a target that's used as a fixture/setup shared across multiple test methods in a test class?

Questions in this quiz
  1. How does `unittest.mock.patch` handle patching a target that's used as a fixture/setup shared across multiple test methods in a test class?
  2. What is the basic behavior of a `Mock` object when you access an attribute or call a method on it that you haven't explicitly configured?
  3. What is a critical, commonly-misunderstood detail about WHERE to point `patch()` — patching where an object is defined versus where it's used?
  4. What is the difference between `Mock` and `MagicMock`?
  5. What is the purpose of `unittest.mock.patch` (often used as a decorator or context manager)?
  6. What does `mock.assert_has_calls([call(1), call(2)])` verify, as opposed to `assert_called_with`?
  7. What is `PropertyMock` used for?
  8. What does `mock.reset_mock()` do?
  9. What is a reasonable justification for writing a test that mocks a third-party HTTP API client, rather than making a real network call to that API during the test?
  10. What does `mock.assert_called_once_with(arg1, arg2)` verify?
  11. What is `Mock.side_effect` used for, beyond what `return_value` covers?
  12. What is `create_autospec()` and how does it differ from `Mock(spec=SomeClass)`?
Gaps to close?
Read the curated Mock notes — core concepts, patterns, interview prep.
Mock notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web