I was recently added to a project to add test coverage (Python/Django unittest module). This app deals heavily with web APIs and JSON requests and such, and part of my job is to make sure that none of the existing or future tests require live network data to function.
What I'd like to know is - is there a way I can wrap my test suite to detect all attempts at network traffic?
As an example, for an earlier portion of this app I overwrote sys.stdout as a way to detect and catch when any submodules wrote to stdout. Is there something as simple I can do to catch attempts at network access by my tests?
EDIT: I appreciate the quick responses. Pulling the cable is of course a simple solution, but I'm afraid breaking my network connection isn't an option (much of the work is over SSH).
I am somewhat familiar with tools like Wireshark but I was hoping for something that could be intelligently integrated with the code itself. jcollado's urlopen patch could potentially be what I'm looking for, but if not it looks like a general network monitor tool might be good enough.