It seems like this could be factored out to a common module, e.g. `astropy/tests/helper.py`.