Fix tests

We need to stop the SparkContexts before creating a new one.
Otherwise the tests get into bad states.