How should bathroom breaks be handled during written exams to avoid cheating? It seems to me that it is impossible to prevent cheating (as in: communicating and getting help from outside) if one allows students to use the restroom during written classroom tests.

Excluding creative solutions involving full-body searches, Faraday cages or invigilators in the stalls, the most practical way to prevent it seems to completely forbid the students to leave the room.

Of course, this seems overly penalizing to students with small health problems or personal emergencies, since they would have to retake the test.

How is this problem dealt with in practice in universities? What is the best solution?
How do other uni's deal with this?
I've attended courses in two universities and have been an exam supervisor in another academical institution.
In all those cases only one student could go to the bathroom at a time.
A supervisor would accompany the student up to the bathroom door and wait until the student would return.
Sure, the student could hide a book, laptop, anything in the toilet stall.
If it's a good exam these methods are not going to get the student anywhere as a good academical test requires that the student can use his brain, not just reproduce knowledge from a book.
Therefore I think making a big deal of cheat prevention is not necessary.
What's the best solution?
Not allowing students to take bathroom breaks is inhumane. I think the solution I experienced and described above is the best you'll get without exaggerating.