def METHOD_NAME(qtbot, request):
    """Set up kernel connection dialog."""
    class DialogFactory(object):
        def get_default_dialog(self):
            dialog = KernelConnectionDialog()
            request.addfinalizer(dialog.close)
            return dialog
        def submit_filled_dialog(self, use_keyfile, save_settings):
            dlg = self.get_default_dialog()
            # fill out cf path
            dlg.cf.clear()
            qtbot.keyClicks(dlg.cf, pytest.cf_path)
            # check the remote kernel box
            dlg.rm_group.setChecked(True)
            # fill out hostname
            dlg.hn.clear()
            qtbot.keyClicks(dlg.hn, pytest.hn)
            # fill out port
            dlg.pn.clear()
            qtbot.keyClicks(dlg.pn, str(pytest.pn))
            # fill out username
            dlg.un.clear()
            qtbot.keyClicks(dlg.un, pytest.un)
            if use_keyfile:
                # select ssh keyfile radio
                dlg.kf_radio.setChecked(True)
                assert dlg.kf.isEnabled()
                # fill out ssh keyfile
                dlg.kf.clear()
                qtbot.keyClicks(dlg.kf, pytest.kf)
                # fill out passphrase
                dlg.kfp.clear()
                qtbot.keyClicks(dlg.kfp, pytest.kfp)
            else:
                # select password radio
                dlg.pw_radio.setChecked(True)
                assert dlg.pw.isEnabled()
                # fill out password
                dlg.pw.clear()
                qtbot.keyClicks(dlg.pw, pytest.pw)
            # check save connection settings
            dlg.save_layout.setChecked(save_settings)
            return dlg
    def teardown():
        """Clear existing-kernel config and keyring passwords."""
        CONF.remove_section("existing-kernel")
        try:
            import keyring
            keyring.set_password("spyder_remote_kernel",
                                 "ssh_key_passphrase", "")
            keyring.set_password("spyder_remote_kernel",
                                 "ssh_password", "")
        except Exception:
            pass
    # test form values
    pytest.cf_path = "cf_path"
    pytest.un = "test_username"
    pytest.hn = "test_hostname"
    pytest.pn = 123
    pytest.kf = "test_kf"
    pytest.kfp = "test_kfp"
    pytest.pw = "test_pw"
    request.addfinalizer(teardown)
    return DialogFactory()