Before I learned about context managers, I had done this urllib substitution stuff myself, figuring that it was just unit tests, so didn't have to be robust w.r.t. exceptions and such.  But now this is much cleaner.  For each test, override the urllib handler, and then fix back up on the way out.