What is mocking, and how do you do it in Python tests?
Model answer
Replacing a real dependency (network, database, clock) with a fake during a test. unittest.mock.patch swaps an object temporarily, and pytest's monkeypatch fixture changes attributes or environment variables. Mock at the boundary, and avoid mocking the code you are testing.
Learn this topic
Mini Project: Analyse a CSV File and Make a Report in the course Python for Beginners: Learn to Code with Real Projects.
Sign in to add your own answer.