Quit the browser with a with statement
Automation taskEasy-MediumPython onlyAsked in: Accenture, TCS, Wipro
Interviewers ask: "How do you make sure the browser always closes, even when the test fails?" In Python, a with block quits the driver for you when the block ends, even after an error (the driver works as a context manager, an object that cleans up when the block ends). A finally block, or a pytest fixture (a setup and clean-up function) that quits after yield, does the same job.