Integration tests - flake8 fixes to core files (rebased)

See gh-2278 To test the two relevant files should pass flake8 and the integration tests should pass (barring usual intermittent failures).

--rebased-from #2278