def METHOD_NAME(kernel_list, state_name):
    """
    Test - latest_installed when an upgrade is available
    """
    installed = MagicMock(return_value=kernel_list[:-1])
    upgrade = MagicMock(return_value=kernel_list[-1])
    with patch.dict(kernelpkg.__salt__, {"kernelpkg.list_installed": installed}):
        with patch.dict(kernelpkg.__salt__, {"kernelpkg.latest_available": upgrade}):
            with patch.dict(kernelpkg.__opts__, {"test": False}):
                kernelpkg.__salt__["kernelpkg.upgrade"].reset_mock()
                ret = kernelpkg.latest_installed(name=state_name)
                assert ret["name"] == state_name
                assert ret["result"]
                assert isinstance(ret["changes"], dict)
                assert isinstance(ret["comment"], str)
                kernelpkg.__salt__["kernelpkg.upgrade"].assert_called_once()
            with patch.dict(kernelpkg.__opts__, {"test": True}):
                kernelpkg.__salt__["kernelpkg.upgrade"].reset_mock()
                ret = kernelpkg.latest_installed(name=state_name)
                assert ret["name"] == state_name
                assert ret["result"] is None
                assert ret["changes"] == {}
                assert isinstance(ret["comment"], str)
                kernelpkg.__salt__["kernelpkg.upgrade"].assert_not_called()