Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Use a temporary config directory to run our tests #6262

Merged
merged 3 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

# Standard library imports
import os
import os.path as osp
import shutil

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

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

# To run our slow tests only in our CIs
run_slow = False
Expand All @@ -30,6 +34,12 @@ def main():
"""
Run pytest tests.
"""
# Remove temp conf_dir before starting the tests
from spyder.config.base import get_conf_path
conf_dir = get_conf_path()
if osp.isdir(conf_dir):
shutil.rmtree(conf_dir)

pytest_args = ['spyder',
'spyder_profiler',
'-x',
Expand Down
6 changes: 5 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import os
import os.path as osp
from sys import version_info
import shutil
import tempfile
try:
Expand Down Expand Up @@ -84,12 +83,14 @@ def open_file_in_editor(main_window, fname, directory=None):
input_field.setText(fname)
QTest.keyClick(w, Qt.Key_Enter)


def get_thirdparty_plugin(main_window, plugin_title):
"""Get a reference to the thirdparty plugin with the title given."""
for plugin in main_window.thirdparty_plugins:
if plugin.get_plugin_title() == plugin_title:
return plugin


def reset_run_code(qtbot, shell, code_editor, nsb):
"""Reset state after a run code test"""
with qtbot.waitSignal(shell.executed):
Expand Down Expand Up @@ -142,9 +143,12 @@ def main_window(request):
app = initialize()
options, args = get_options()
window = run_spyder(app, options, args)

# Teardown
def close_window():
window.close()
request.addfinalizer(close_window)

return window


Expand Down
20 changes: 16 additions & 4 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ def get_home_dir():

def get_conf_path(filename=None):
"""Return absolute path for configuration file with specified filename"""
# This makes us follow the XDG standard to save our settings
# on Linux, as it was requested on Issue 2629
if sys.platform.startswith('linux'):
# Define conf_dir
if PYTEST:
import py
from _pytest.tmpdir import get_user
conf_dir = osp.join(str(py.path.local.get_temproot()),
'pytest-of-{}'.format(get_user()),
SUBFOLDER)
elif sys.platform.startswith('linux'):
# This makes us follow the XDG standard to save our settings
# on Linux, as it was requested on Issue 2629
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
if not xdg_config_home:
xdg_config_home = osp.join(get_home_dir(), '.config')
Expand All @@ -129,8 +136,13 @@ def get_conf_path(filename=None):
conf_dir = osp.join(xdg_config_home, SUBFOLDER)
else:
conf_dir = osp.join(get_home_dir(), SUBFOLDER)

# Create conf_dir
if not osp.isdir(conf_dir):
os.mkdir(conf_dir)
if PYTEST:
os.makedirs(conf_dir)
else:
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
Expand Down