def test_write_config(exists: MagicMock, isfile: MagicMock, makedirs: MagicMock, open: MagicMock, yaml_dump: MagicMock, safe_print: MagicMock):
    exists.return_value = True
    isfile.return_value = True

    config_management.write_config({'key': 'value'})

    yaml_dump.assert_called_once_with({'key': 'value'}, open.return_value, width=1000)
    makedirs.assert_not_called()
    open.assert_called_once()
def test_write_config_catches_exception(exists: MagicMock, isfile: MagicMock, makedirs: MagicMock, open: MagicMock, yaml_dump: MagicMock, safe_print: MagicMock):
    exists.return_value = True
    isfile.return_value = False
    yaml_dump.side_effect = Exception()

    config_management.write_config({'key': 'value'})

    makedirs.assert_not_called()
    safe_print.assert_called()
    assert open.call_count == 2