def testMigrateTimesOut(monkeypatch): monkeypatch.setattr(migration_tool, '_call_migration_script', lambda *x: exec('raise(TimeoutError())')) monkeypatch.setattr(migration_tool, '_get_migration_scripts', lambda *x: TEST_MIGRATION_SCRIPTS) with pytest.raises(TimeoutError): migration_tool.migrate(TEST_VERSION, TEST_NEW_VERSION, TEST_TIMEOUT)
def testMigrate(monkeypatch): testList = [] monkeypatch.setattr(importlib, 'import_module', testList.append) monkeypatch.setattr(migration_tool, '_get_migration_scripts', lambda *x: TEST_MIGRATION_SCRIPTS) assert migration_tool.migrate(TEST_VERSION, TEST_NEW_VERSION, TEST_TIMEOUT) == 3 assert len(testList) == 3
def testMigrate(monkeypatch): testList = [] monkeypatch.setattr(migration_tool, '_call_migration_script', lambda *x: testList.append(x[0])) monkeypatch.setattr(migration_tool, '_get_migration_scripts', lambda *x: TEST_MIGRATION_SCRIPTS) assert migration_tool.migrate(TEST_VERSION, TEST_NEW_VERSION, TEST_TIMEOUT) == 3 assert len(testList) == 3
def _migrate(self, current_version, new_version): migrate(current_version, new_version, self.timeout)
def testMigrateTimesOut(monkeypatch): monkeypatch.setattr(importlib, 'import_module', lambda *x: time.sleep(TEST_TIMEOUT * 2)) monkeypatch.setattr(migration_tool, '_get_migration_scripts', lambda *x: TEST_MIGRATION_SCRIPTS) with pytest.raises(TimeoutError): migration_tool.migrate(TEST_VERSION, TEST_NEW_VERSION, TEST_TIMEOUT)