Testing models for molecular gas formation in galaxies: Hydrostatic pressure or gas and dust shielding