Skip to content

Commit a771d31

Browse files
authored
Merge pull request #6262 from ccordoba12/use-tmp-confdir-for-tests
PR: Use a temporary config directory to run our tests
2 parents 50f9043 + 1b141be commit a771d31

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Diff for: runtests.py

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Standard library imports
1212
import os
13+
import os.path as osp
14+
import shutil
1315

1416
# Third party imports
1517
import qtpy # to ensure that Qt4 uses API v2
@@ -19,6 +21,8 @@
1921
# To activate/deactivate certain things for pytest's only
2022
os.environ['SPYDER_PYTEST'] = 'True'
2123

24+
# Tests expect English as the interface language
25+
os.environ['LANG'] = 'en'
2226

2327
# To run our slow tests only in our CIs
2428
run_slow = False
@@ -30,6 +34,12 @@ def main():
3034
"""
3135
Run pytest tests.
3236
"""
37+
# Remove temp conf_dir before starting the tests
38+
from spyder.config.base import get_conf_path
39+
conf_dir = get_conf_path()
40+
if osp.isdir(conf_dir):
41+
shutil.rmtree(conf_dir)
42+
3343
pytest_args = ['spyder',
3444
'spyder_profiler',
3545
'-x',

Diff for: spyder/app/tests/test_mainwindow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import os
1212
import os.path as osp
13-
from sys import version_info
1413
import shutil
1514
import tempfile
1615
try:
@@ -84,12 +83,14 @@ def open_file_in_editor(main_window, fname, directory=None):
8483
input_field.setText(fname)
8584
QTest.keyClick(w, Qt.Key_Enter)
8685

86+
8787
def get_thirdparty_plugin(main_window, plugin_title):
8888
"""Get a reference to the thirdparty plugin with the title given."""
8989
for plugin in main_window.thirdparty_plugins:
9090
if plugin.get_plugin_title() == plugin_title:
9191
return plugin
9292

93+
9394
def reset_run_code(qtbot, shell, code_editor, nsb):
9495
"""Reset state after a run code test"""
9596
with qtbot.waitSignal(shell.executed):
@@ -142,9 +143,12 @@ def main_window(request):
142143
app = initialize()
143144
options, args = get_options()
144145
window = run_spyder(app, options, args)
146+
147+
# Teardown
145148
def close_window():
146149
window.close()
147150
request.addfinalizer(close_window)
151+
148152
return window
149153

150154

Diff for: spyder/config/base.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,16 @@ def get_home_dir():
118118

119119
def get_conf_path(filename=None):
120120
"""Return absolute path for configuration file with specified filename"""
121-
# This makes us follow the XDG standard to save our settings
122-
# on Linux, as it was requested on Issue 2629
123-
if sys.platform.startswith('linux'):
121+
# Define conf_dir
122+
if PYTEST:
123+
import py
124+
from _pytest.tmpdir import get_user
125+
conf_dir = osp.join(str(py.path.local.get_temproot()),
126+
'pytest-of-{}'.format(get_user()),
127+
SUBFOLDER)
128+
elif sys.platform.startswith('linux'):
129+
# This makes us follow the XDG standard to save our settings
130+
# on Linux, as it was requested on Issue 2629
124131
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
125132
if not xdg_config_home:
126133
xdg_config_home = osp.join(get_home_dir(), '.config')
@@ -129,8 +136,13 @@ def get_conf_path(filename=None):
129136
conf_dir = osp.join(xdg_config_home, SUBFOLDER)
130137
else:
131138
conf_dir = osp.join(get_home_dir(), SUBFOLDER)
139+
140+
# Create conf_dir
132141
if not osp.isdir(conf_dir):
133-
os.mkdir(conf_dir)
142+
if PYTEST:
143+
os.makedirs(conf_dir)
144+
else:
145+
os.mkdir(conf_dir)
134146
if filename is None:
135147
return conf_dir
136148
else:

0 commit comments

Comments
 (0)