def setUp(self): run_pip_patch = mock.patch("ensurepip._run_pip") self.run_pip = run_pip_patch.start() self.addCleanup(run_pip_patch.stop) # Avoid side effects on the actual os module real_devnull = os.devnull os_patch = mock.patch("ensurepip.os") patched_os = os_patch.start() self.addCleanup(os_patch.stop) patched_os.devnull = real_devnull patched_os.path = os.path self.os_environ = patched_os.environ = os.environ.copy()