Various fixes for test running

Fix #1199