Lil Scrappy believes he's addicted to weed ... and after failing a court-ordered drug test, the rapper will enter a rehab facility for treatment, TMZ has learned.

Scrappy appeared in a Georgia courtroom moments ago, where officials revealed a urine test Scrappy took last week came back positive for marijuana.

TMZ spoke with Scrappy's lawyer, Mawuli Mel Davis, who tells us ... the rapper will check into a rehab facility before the next court hearing in June.

Davis also tells
us ... Scrappy acknowledges he's addicted to smoking marijuana.
We broke the story ... Scrappy was recently jailed for violating his probation back in March after a dispute over a different pee test. According to court officials, Scrappy tried to turn in a urine sample that was cold to the touch and may have been tampered with ... and when asked to submit another cup, he refused.