Can a UTI affect a pregnancy test? Unfortunately it's a yes and no answer.
The "yes" part - if you are urinating more frequently, when testing early on, the level of hCG is so low that it may not be concentrated enough to detect. You could be pregnant and have a false negative result.
The "no" part - False positives are VERY rare. The tests only look for hCG, the pregnancy hormone, in your urine. If the levels are high enough for the test to respond then it will indicate pregnancy.
I'd suggest you retest and use your first morning urine - wake up pee. This is the most concentrated urine of the day typically and should give you the earliest and most reliable result.