Repository: spyder-ide/spyder

Issue:
Error while restarting kernel
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When I restart my kernel I get this error:

```python-traceback
Traceback (most recent call last):
  File "/home/user/spyder/spyder/plugins/ipythonconsole/plugin.py", line 1661, in restart_kernel
    stderr = self.get_stderr_file_handle(stderr_file)
AttributeError: 'IPythonConsole' object has no attribute 'get_stderr_file_handle
```

I think there shouldn't be a `self` in there. But when I fixed that, then I get:
```python-traceback
Traceback (most recent call last):
  File "/home/bcolsen/spyder/spyder/plugins/ipythonconsole/plugin.py", line 1663, in restart_kernel
    client.restart_kernel(stderr=stderr)
TypeError: restart_kernel() got an unexpected keyword argument 'stderr'
```
`client.restart_kernel` doesn't have any args so I'm not sure what this code is supposed to do.

I think #7829 was the last PR in this section.

### What steps reproduce the problem?

1. restart the kernel

### What is the expected output? What do you see instead?

doesn't restart


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
  File "/home/user/spyder/spyder/plugins/ipythonconsole/plugin.py", line 1661, in restart_kernel
    stderr = self.get_stderr_file_handle(stderr_file)
AttributeError: 'IPythonConsole' object has no attribute 'get_stderr_file_handle

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.0.dev0 (Commit: 39245fb) 
* Python version: 3.6.5 64-bit
* Qt version: 5.9.4
* PyQt version: 5.9.2
* Operating System name/version: Linux

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

``` 
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
psutil >=0.3      :  5.4.6 (OK)
pyls >=0.19.0     :  0.19.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.23.1 (OK)
numpy >=1.7       :  1.14.5 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.28.3 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0     :  6.4.0 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.9.2 (OK)
```



Discussion:
I don't understand why our tests didn't detect this regression. But I'll fix it today for sure.
I had a look at the test. It looks like it only covers `Client.restart_kernel` which work fine.
I see, so we need to test also at the plugin level.

Since I was the one who wrote that test, shame on me ;-p

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -1588,18 +1588,9 @@ def create_kernel_manager_and_kernel_client(self, connection_file,
     def restart_kernel(self):
         """Restart kernel of current client."""
         client = self.get_current_client()
-        if self.test_no_stderr:
-            stderr_file = None
-        else:
-            stderr_file = client.stderr_file
 
         if client is not None:
-            stderr = self.get_stderr_file_handle(stderr_file)
-            try:
-                client.restart_kernel(stderr=stderr)
-            finally:
-                if stderr is not None:
-                    stderr.close()
+            client.restart_kernel()
 
     #------ Public API (for tabs) ---------------------------------------------
     def add_tab(self, widget, name, filename=''):
diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py
--- a/spyder/widgets/ipythonconsole/client.py
+++ b/spyder/widgets/ipythonconsole/client.py
@@ -483,8 +483,8 @@ def restart_kernel(self):
             result = None
 
         if (result == QMessageBox.Yes or
-           running_under_pytest() or
-           not self.ask_before_restart):
+                running_under_pytest() or
+                not self.ask_before_restart):
             if sw.kernel_manager:
                 if self.infowidget.isVisible():
                     self.infowidget.hide()


Test patch:
diff --git a/spyder/plugins/tests/test_ipythonconsole.py b/spyder/plugins/tests/test_ipythonconsole.py
--- a/spyder/plugins/tests/test_ipythonconsole.py
+++ b/spyder/plugins/tests/test_ipythonconsole.py
@@ -733,7 +733,6 @@ def test_restart_kernel(ipyconsole, qtbot):
     Test that kernel is restarted correctly
     """
     shell = ipyconsole.get_current_shellwidget()
-    client = ipyconsole.get_current_client()
     qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
 
     # Do an assignment to verify that it's not there after restarting
@@ -742,7 +741,7 @@ def test_restart_kernel(ipyconsole, qtbot):
 
     # Restart kernel and wait until it's up again
     shell._prompt_html = None
-    client.restart_kernel()
+    ipyconsole.restart_kernel()
     qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
 
     assert 'Restarting kernel...' in shell._control.toPlainText()