Most of the mathematical formlities are dealt with on the wikipedia page you reference in your question. There, to prove the shell theorem, the shell is taken to have mass per unit area $\sigma$ and split it up into lots of coaxial rings, with the axis running along a diameter that goes through the test mass. $\theta$ is the angle between the diameter through the test mass and a line from the centre of the sphere to one of the rings.
Skipping to the main point, we can find the gravitational field generated by one of the thin rings at a test position that is a distance $r$ from the centre of a sphere of radius $R$ and mass $M$, where $s$ is the distance from the test position to a point on the ring is given by
$$dg = \frac{GM}{4Rr^2}\left( 1 - \frac{R^2-r^2}{s^2}\right)\ ds$$
which integrates to
$$g = \left[\frac{GM}{4Rr^2}\left(s + \frac{R^2 - r^2}{s}\right)\right]^{s_{\rm max}}_{s_{\rm min}}.$$
For the full spherical shell the limits are $s_{\rm min} = R-r$ (when $\theta=0$) to $s_{\rm max}=R+r$ (when $\theta=\pi$ and the result is zero - this is the shell theorem and should work for any value of $r\leq R$.
However to answer your specific question, why doesn't the gravitational field due to the piece of the shell closest to the test point blow-up towards infinity as the test point gets very close to the surface of the shell and overwhelm the opposite (but clearly finite) field generated by the mass distributed over the rest of the sphere?
Look at the equation above and how it behaves when $r$ is very close to (but smaller than) $R$. In this case $s_{\rm min} \simeq 0$, and $(R^2-r^2)/s \simeq 2R$ resulting in a finite lower limit.
In words what is happening is that the amount of mass that is "infinitesimally close" to the test mass becomes infinitesimally small, ensuring that the gravitational effect of this mass does not blow up to infinity.