Less verbose tests Fixes #2453 and deduplicates some related code.
Strictly speaking this is not a true deduplication; the test output will be slightly different (due to inconsistent print statements) but I think this is close enough.