It's have no bearing on the trial if he was pleading not guilty. Wouldn't normally be admissable because it has no bearing on the issue of whether or not he was in possession on the day concerned.
Generally, people use it in their plea of mitigation. (The attempt to get as light a sentence as possible after you plead or have been found guilty.)
"Yes, you have found my client guilty of possessing an ounce of low quality nigger-supplied yayo. But at the time when he is accused of possessing said product, my client was deep in the depths of a cocaine addiction. Since then, he has signed himself into Drugz-be-gon -- a notable seven day combined detox and rehabilitation facility aimed specifically at the recipients of trust funders, so there are no poors to tempt my client into relapse. Drugz-be-gon have treated and cured his cocaine addiction he has turned in clean urine samples for the last two days, so we can safely say he is completely cured and will never be a bad boy again. Therefore, I ask that you give my client a $100 fine and a complete discharge if he stays free of all drug use for the next two weeks. "
In the absence of a guilty plea though, a plea of mitigation like this is unlikely to cut much ice. Courts want to see some evidence of recovery. That would involve admitting your previous flaws and errors. They'd see a not guilty plea as a refusal to do that and so would probably be very sceptical of the recovery narrative.