title: Python: block network connections for testing purposes?
body: <p>I'm trying to test a package that provides interfaces to a few web services.  It has a test suite that is supposed to test most functions <em>without</em> connecting to the internet.  However, there are some lingering tests that may attempt to connect to the internet / download data, and I'd like to prevent them from doing so for two reasons: first, to make sure my test suite works if no network connection is available; second, so that I'm not spamming the web services with excess queries.</p>
  
  <p>An obvious solution is to unplug my machine / turn off wireless, but when I'm running tests on a remote machine that obviously doesn't work.</p>
  
  <p>So, my question: Can I block network / port access for a single python process?  ("sandbox" it, but just blocking network connections)</p>
  
  <p>(afaict, pysandbox doesn't do this)</p>
  
  <p>EDIT: I'm using <code>py.test</code> so I need a solution that will work with <code>py.test</code>, in case that affects any proposed answers.</p>