L.R.
So if she's fine medically, and does not wet herself, or wet the bed at night...I'm assuming here you've cut out caffeinated and highly sugared drinks too, both of which can cause the "I need to pee" feeling?
If you've done all that: Have you considered having her evaluated for the anxiety itself, as opposed to looking just at physical causes?
Five months of this is far, far too long and she must be extremely stressed out. It sounds like she may be "feeling" she needs to urinate when her body does not need to urinate. I'm not denying that she truly believes she needs to pee; but she doesn't know how to interpret the real feeling of a need for urination. And her sheer fear of wetting herself is way beyond what most kids would exhibit, it seems. Why is it so extreme? That's what you need help answering.
This could be emotional or psychological -- not a big thing but perhaps the result of one embarrassing accident a while back, or if not that, find out if maybe she had a friend who had an accident at school and got teased about it, or even if she's possibly using "I can't leave, I just have to pee" as an unconscious excuse to avoid going out? If that's the case, she might have some form of social anxiety. Maybe she does get upset that she can't go out to do X because she has to sit on the toilet - but if she really, really wanted to go do X or leave the house, she'd do what many other kids do -- go anyway and get so involved and excited she'd really need to pee and forget to do it!
I'd talk to the pediatrician now for fast referral to a counselor who specializes in kids. It's been five months; time to get her some help coping with the fear she's feeling. I say "fast" because once schools starts iin the fall, how on earth will she and you and the teacher cope with this?