Fixed test_scheduler on ub18
@@ -39,6 +39,12 @@ async def mock_process():
@pytest.allure.story("scheduler")
class TestScheduler:
async def scheduler_fixture(self, mocker):
+ # Changed in version 3.8: patch() now returns an AsyncMock if the target is an async function.
+ if sys.version_info.major == 3 and sys.version_info.minor >= 8:
+ _rv = await mock_process()
+ else:
+ _rv = asyncio.ensure_future(mock_process())
+
scheduler = Scheduler()
scheduler._storage = MockStorage(core_management_host=None, core_management_port=None)
scheduler._storage_async = MockStorageAsync(core_management_host=None, core_management_port=None)
@@ -48,7 +54,7 @@ class TestScheduler:
mocker.patch.object(scheduler, '_process_scripts', return_value="North Readings to PI")
mocker.patch.object(scheduler, '_wait_for_task_completion', return_value=asyncio.ensure_future(mock_task()))
mocker.patch.object(scheduler, '_terminate_child_processes')
- mocker.patch.object(asyncio, 'create_subprocess_exec', return_value=(await mock_process()))
+ mocker.patch.object(asyncio, 'create_subprocess_exec', return_value=(_rv))
await scheduler._get_schedules()
@@ -180,7 +186,13 @@ class TestScheduler:
await scheduler.queue_task(schedule.id)
assert isinstance(scheduler._schedule_executions[schedule.id], scheduler._ScheduleExecution)
- mocker.patch.object(asyncio, 'create_subprocess_exec', return_value=(await mock_process()))
+ # Changed in version 3.8: patch() now returns an AsyncMock if the target is an async function.
+ if sys.version_info.major == 3 and sys.version_info.minor >= 8:
+ _rv = await mock_process()
+ else:
+ _rv = asyncio.ensure_future(mock_process())
+
+ mocker.patch.object(asyncio, 'create_subprocess_exec', return_value=(_rv))
mocker.patch.object(asyncio, 'ensure_future', return_value=asyncio.ensure_future(mock_task()))
mocker.patch.object(scheduler, '_resume_check_schedules')
mocker.patch.object(scheduler, '_process_scripts', return_value="North Readings to PI")
