def call_runscheduler(loops=1, mock_call_command=None):
ctx = {'sleep_count': 0}
def fake_sleep(seconds):
ctx['sleep_count'] += 1
if ctx['sleep_count'] > loops:
raise KeyboardInterrupt()
if mock_call_command is None:
mock_call_command = mock.MagicMock()
with mock.patch.object(runscheduler, 'call_command', mock_call_command):
with mock.patch.object(runscheduler, 'logger') as mock_logger:
with mock.patch('time.sleep', fake_sleep):
with pytest.raises(KeyboardInterrupt):
call_command('runscheduler')
return mock_call_command, mock_logger
评论列表
文章目录