Merge "Monkey-patch in tests using mock.patch"

This commit is contained in:
Zuul
2021-01-17 02:53:06 +00:00
committed by Gerrit Code Review

View File

@@ -1382,16 +1382,11 @@ class TestServer(unittest.TestCase):
def sleep(self, *args, **kwargs):
pass
with temptree([]) as t:
old_stdout = sys.stdout
old_wait = manager.WARNING_WAIT
old_time = manager.time
try:
manager.WARNING_WAIT = 0.01
manager.time = MockTime()
with open(os.path.join(t, 'output'), 'w+') as f:
# actually capture the read stdout (for prints)
sys.stdout = f
with temptree([]) as t, open(os.path.join(t, 'output'), 'w+') as f, \
mock.patch.object(sys, 'stdout', f), \
mock.patch.object(manager, 'WARNING_WAIT', 0.01), \
mock.patch.object(manager, 'time', MockTime()):
# Note that we actually capture the read stdout (for prints)
# test closing pipe in subprocess unblocks read
with MockProcess() as proc:
server.procs = [proc]
@@ -1427,10 +1422,6 @@ class TestServer(unittest.TestCase):
self.assertTrue(proc.is_alive())
for proc in procs:
proc.join()
finally:
sys.stdout = old_stdout
manager.WARNING_WAIT = old_wait
manager.time = old_time
def test_interact(self):
class MockProcess(object):