Numerous states now use the OBDII readiness monitors and the check engine light as a prerequisite to or the only condition to testing. Some monitors are run continuously and others only once a drive cycle (IF THE CONDITIONS are right)
Since it is obvious, even to government types, that just because the check engine light is out, the car might not have passed the monitor tests yet BECAUSE someone might have just cleared it. Most of the tests run in a ten miles road test. Some take months some will never test unless the conditions exist. The evap monitor will never run above a certain altitude. It will never run with an empty or full tank. The HFM system was real tight in running the tests and I have had cars that didn't do the relearn of adaptation for months. The car has to get in just the right set of load, rpm, temp, etc., etc..
Most states will accept some percentage or number of monitors, out of the whole. It is very easy to see why they would flunk you if the battery was disconnected.
Since I am not in one of those states I have not had to do this.
Bosch Master, ASE Master, L1
33 years MB technician