Python integration test fixes and introduction of pytest (rebased on develop)

This is rebased from PR #1409 with some minor conflicts fixed.