def test_execute_error_must_pass_through(self, monkeypatch): snowflake_module_connect_method = MagicMock() connection = MagicMock(spec=sf.SnowflakeConnection) cursor = MagicMock(spec=sf.DictCursor) # link all the mocks together appropriately snowflake_module_connect_method.return_value = connection connection.cursor = cursor # database cursors can be ugly to mock given the use of __enter__ cursor.return_value.__enter__.return_value.execute.side_effect = ( sf.DatabaseError("Invalid query")) snowflake_connector_module = MagicMock( connect=snowflake_module_connect_method) monkeypatch.setattr("prefect.tasks.snowflake.snowflake.sf", snowflake_connector_module) task = SnowflakeQuery(account="test", user="******", password="******", warehouse="test") with pytest.raises(sf.errors.DatabaseError, match="Invalid query"): task.run(query="SELECT * FROM foo")
def test_execute_error_must_pass_through(self, monkeypatch, sql_file): connection = MagicMock(spec=sf.SnowflakeConnection) snowflake_module_connect_method = MagicMock(return_value=connection) snowflake_connector_module = MagicMock(connect=snowflake_module_connect_method) # setting error connection.execute_string.side_effect = sf.DatabaseError("Invalid query") monkeypatch.setattr( "prefect.tasks.snowflake.snowflake.sf", snowflake_connector_module ) task = SnowflakeQueriesFromFile( account="test", user="******", password="******", warehouse="test" ) with pytest.raises(sf.errors.DatabaseError, match="Invalid query"): task.run(file_path=sql_file)