There are many cases when you have no luxury of having a full-scale Python project. All you allowed to is to have a self-contained script consisting of a single file. No setup.py, no tox.ini, nothing.
setup.py
tox.ini
When I had tested code which had called sys.exit(), my usual approach was to use mock:
sys.exit()
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
The original title was “Never Write For-Loops Again” but I think it misled people to think that…