Fix getting astropy cosmology for v5.1
The latest version of astropy (5.1) is breaking the tests because of how we're accessing the built-in cosmologies.
This MR fixes that and should make it more robust.
I tested this locally with v5 which is the oldest version we support.