Repository: spyder-ide/spyder

Issue:
Don't save IPython history in safe mode
<!--- **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] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

IPython isn't using a temporary config directory in safe-mode 

### What steps reproduce the problem?

1. run `./bootstrap.py --safe-mode` in spyder 3.x
2. press the up arrow in the ipython console
3. see your history

### What is the expected output? What do you see instead?

I should see nothing


## Versions

* Spyder version: 3.x
* Python version: 3.6



Discussion:

Resolving patch:
diff --git a/spyder/utils/ipython/kernelspec.py b/spyder/utils/ipython/kernelspec.py
--- a/spyder/utils/ipython/kernelspec.py
+++ b/spyder/utils/ipython/kernelspec.py
@@ -13,7 +13,8 @@
 
 from jupyter_client.kernelspec import KernelSpec
 
-from spyder.config.base import get_module_source_path
+from spyder.config.base import (SAFE_MODE, get_module_source_path,
+                                running_under_pytest)
 from spyder.config.main import CONF
 from spyder.utils.encoding import to_unicode_from_fs
 from spyder.utils.programs import is_python_interpreter
@@ -128,7 +129,8 @@ def env(self):
             'SPY_GREEDY_O': CONF.get('ipython_console', 'greedy_completer'),
             'SPY_JEDI_O': CONF.get('ipython_console', 'jedi_completer'),
             'SPY_SYMPY_O': CONF.get('ipython_console', 'symbolic_math'),
-            'SPY_RUN_CYTHON': self.is_cython
+            'SPY_RUN_CYTHON': self.is_cython,
+            'SPY_TESTING': running_under_pytest() or SAFE_MODE
         }
 
         # Add our PYTHONPATH to env_vars
diff --git a/spyder/utils/ipython/start_kernel.py b/spyder/utils/ipython/start_kernel.py
--- a/spyder/utils/ipython/start_kernel.py
+++ b/spyder/utils/ipython/start_kernel.py
@@ -66,13 +66,17 @@ def kernel_config():
     # ---- Spyder config ----
     spy_cfg = Config()
 
+    # Enable/disable certain features for testing
+    testing = os.environ.get('SPY_TESTING') == 'True'
+    if testing:
+        # Don't load nor save history in our IPython consoles.
+        spy_cfg.HistoryAccessor.enabled = False
+
     # Until we implement Issue 1052
     spy_cfg.InteractiveShell.xmode = 'Plain'
 
-    # Jedi completer
+    # Jedi completer. It's only available in Python 3
     jedi_o = os.environ.get('SPY_JEDI_O') == 'True'
-    # - Using Jedi slow completions a lot for objects with big repr's.
-    # - Jedi completions are not available in Python 2.
     if not PY2:
         spy_cfg.IPCompleter.use_jedi = jedi_o
 


Test patch: