[1.7.x] Fixed several flake8 errors, including one where a test wouldn't be run

Backport of b6b873d2ada0d7c2a616d11f161a7688df15f45f from master