Recall & Review
beginner
What is a mock call assertion in pytest?
A mock call assertion checks if a mocked function was called as expected during a test. It helps verify interactions without running real code.
Click to reveal answer
beginner
How do you assert that a mock was called exactly once in pytest?
Use
mock_function.assert_called_once() to check the mock was called exactly one time.Click to reveal answer
beginner
What does
assert_called_with() do in mock assertions?It checks that the mock was called with specific arguments at least once during the test.
Click to reveal answer
intermediate
Explain the difference between
assert_called_once_with() and assert_called_with().assert_called_once_with() checks the mock was called exactly once with the given arguments. assert_called_with() checks the mock was called at least once with those arguments, but can be multiple times.Click to reveal answer
intermediate
How can you check the order of multiple calls to a mock?
Use
mock_function.call_args_list to get a list of all calls in order, then assert each call's arguments.Click to reveal answer
Which method asserts a mock was called exactly once with specific arguments?
✗ Incorrect
assert_called_once_with() checks the mock was called exactly once with the given arguments.What does
mock_function.assert_called() verify?✗ Incorrect
assert_called() verifies the mock was called at least once, regardless of arguments.How do you check if a mock was called with certain arguments at least once?
✗ Incorrect
assert_called_with() checks the mock was called at least once with the specified arguments.Which attribute holds the list of all calls made to a mock?
✗ Incorrect
call_args_list contains all calls made to the mock in order.What happens if
assert_called_once() is used but the mock was called twice?✗ Incorrect
assert_called_once() fails if the mock was called more than once.Describe how to verify a mock function was called with specific arguments exactly once in pytest.
Think about the assertion method that combines call count and arguments.
You got /3 concepts.
Explain how to check the order and arguments of multiple calls made to a mock.
Look for a list that records all calls.
You got /3 concepts.