Test exception conditions
Tidy with flake8