It is narrated from Sayyiduna al-Miswar bin Makhramah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "None of you should pray while he feels any discomfort," meaning the urge to relieve himself of stool or urine.
Hadith Referenceالمعجم الكبير للطبراني / باب الميم / 17158