fix bug 1074201 - refactor test base classes and introduce some more

- this also fixes various issues with tests that improve speed and performance
- includes plenty of stylistic changes like PEP8 updates
Removed as it wasn't working.