Testing sys.exit() with pytest
When I had tested code which had called sys.exit()
, my usual approach was to use mock:
def test_exit(mymodule):
with mock.patch.object(mymodule.sys, "exit") as mock_exit:
mymodule.should_exit()
assert mock_exit.call_args[0][0] == 42