Monkey-patch in tests using mock.patch
Change-Id: Idf2205074e8f12bc0e515c860e9c1bddf59561d1
This commit is contained in:
parent
267d432f86
commit
14a42d573a
@ -1374,16 +1374,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]
|
||||
@ -1419,10 +1414,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):
|
||||
|
Loading…
Reference in New Issue
Block a user