You're tempting fate when you only have half a milligram left and need to test positive. I personally would take it no more than 12 hours before the test and no less than 3. You are technically trying to "beat" a drug test which is in the user agreement. Do yourself a favor next time if you want to continue to take subs, and use the prescribed dose (or less if you get more than 8mg per day, but try not to go less than half) and do not stop taking it, even if only to occasionally use other opiates. If you are prescribed it, I have a hard time figuring out why you have so little left unless you were selling. If I'm wrong, good, but adherence to the program is the best way to benefit from the use of buprenorphine.