Environmental effects on the detection of adaptation