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: Check tests robustness, number of concurrent jobs and try to decrease segfault failures on CI #17622

Merged
merged 7 commits into from
Apr 21, 2022
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 .github/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ if [ "$USE_CONDA" = "true" ]; then
conda remove $dep --force -q -y
fi
done

# Install jupyter_client 7.2.0 to prevent ZMQ Socket operation on non-socket
# Remove this when the issue is fixed upstream most probaly with jupyter_client=7.2.3
# See https://github.com/spyder-ide/spyder/issues/17615
mamba install jupyter_client=7.2.0 -c conda-forge -q -y
else
# Update pip and setuptools
pip install -U pip setuptools
Expand All @@ -56,6 +61,11 @@ else
pip uninstall $dep -q -y
done

# Install jupyter_client 7.2.0 to prevent ZMQ Socket operation on non-socket
# Remove this when the issue is fixed upstream most probaly with jupyter_client=7.2.3
# See https://github.com/spyder-ide/spyder/issues/17615
pip install -q jupyter_client==7.2.0

# Remove Spyder to properly install it below
pip uninstall spyder -q -y
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
fail-fast: false
matrix:
INSTALL_TYPE: ['pip']
PYTHON_VERSION: ['3.7']
PYTHON_VERSION: ['3.9']
TEST_TYPE: ['fast', 'slow']
timeout-minutes: 120
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
fail-fast: false
matrix:
INSTALL_TYPE: ['pip', 'conda']
PYTHON_VERSION: ['3.7', '3.9']
PYTHON_VERSION: ['3.9']
TEST_TYPE: ['fast', 'slow']
timeout-minutes: 120
steps:
Expand Down
2 changes: 1 addition & 1 deletion spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def post_visible_setup(self):
if (CONF.get('main', 'single_instance') and not self.new_instance
and self.open_files_server):
t = threading.Thread(target=self.start_open_files_server)
t.setDaemon(True)
t.daemon = True
t.start()

# Connect the window to the signal emitted by the previous server
Expand Down
50 changes: 36 additions & 14 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ def check_control(control, value):
return value in control.toPlainText()

qtbot.keyClicks(control, u'aa\t')
qtbot.waitUntil(lambda: check_control(control, u'aaʹbb'), timeout=2000)
qtbot.waitUntil(lambda: check_control(control, u'aaʹbb'),
timeout=SHELL_TIMEOUT)

# Get help
control.inspect_current_object()
Expand Down Expand Up @@ -1091,6 +1092,7 @@ def test_runconfig_workdir(main_window, qtbot, tmpdir):


@pytest.mark.slow
@pytest.mark.order(1)
@pytest.mark.no_new_console
@flaky(max_runs=3)
def test_dedicated_consoles(main_window, qtbot):
Expand Down Expand Up @@ -2169,6 +2171,9 @@ def test_plots_plugin(main_window, qtbot, tmpdir, mocker):
(parse_version(ipy_release.version) >= parse_version('7.23.0') and
parse_version(ipykernel.__version__) <= parse_version('5.5.3')),
reason="Fails due to a bug in the %matplotlib magic")
@pytest.mark.skipif(
sys.platform.startswith('linux'),
reason="Timeouts a lot on Linux")
def test_tight_layout_option_for_inline_plot(main_window, qtbot, tmpdir):
"""
Test that the option to set bbox_inches to 'tight' or 'None' is
Expand Down Expand Up @@ -2235,9 +2240,10 @@ def test_tight_layout_option_for_inline_plot(main_window, qtbot, tmpdir):
CONF.set('ipython_console', 'pylab/inline/bbox_inches', False)

# Restart the kernel and wait until it's up again
shell._prompt_html = None
client.restart_kernel()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
with qtbot.waitSignal(client.sig_execution_state_changed,
timeout=SHELL_TIMEOUT):
client.restart_kernel()
qtbot.waitUntil(lambda: 'In [1]:' in control.toPlainText(),
timeout=SHELL_TIMEOUT)

# Generate the same plot inline with bbox_inches='tight' and save the
Expand Down Expand Up @@ -2476,6 +2482,9 @@ def test_troubleshooting_menu_item_and_url(main_window, qtbot, monkeypatch):
@flaky(max_runs=3)
@pytest.mark.slow
@pytest.mark.skipif(os.name == 'nt', reason="It fails on Windows")
@pytest.mark.skipif(
sys.platform == 'darwin' and running_in_ci(),
reason="It stalls the CI sometimes on MacOS")
def test_help_opens_when_show_tutorial_full(main_window, qtbot):
"""
Test fix for spyder-ide/spyder#6317.
Expand Down Expand Up @@ -3835,14 +3844,25 @@ def test_run_unsaved_file_multiprocessing(main_window, qtbot):
# create new file
main_window.editor.new()
code_editor = main_window.editor.get_focus_widget()
code_editor.set_text(
"import multiprocessing\n"
"import traceback\n"
'if __name__ is "__main__":\n'
" p = multiprocessing.Process(target=traceback.print_exc)\n"
" p.start()\n"
" p.join()\n"
)
if sys.platform == 'darwin':
# Since Python 3.8 MacOS uses by default `spawn` instead of `fork`
# and that causes problems.
# See https://stackoverflow.com/a/65666298/15954282
text = ("import multiprocessing\n"
'multiprocessing.set_start_method("fork")\n'
"import traceback\n"
'if __name__ == "__main__":\n'
" p = multiprocessing.Process(target=traceback.print_exc)\n"
" p.start()\n"
" p.join()\n")
else:
text = ("import multiprocessing\n"
"import traceback\n"
'if __name__ == "__main__":\n'
" p = multiprocessing.Process(target=traceback.print_exc)\n"
" p.start()\n"
" p.join()\n")
code_editor.set_text(text)
# This code should run even on windows

# Start running
Expand All @@ -3853,11 +3873,13 @@ def test_run_unsaved_file_multiprocessing(main_window, qtbot):
# be broken.
if os.name == 'nt':
qtbot.waitUntil(
lambda: "Warning: multiprocessing" in shell._control.toPlainText())
lambda: "Warning: multiprocessing" in shell._control.toPlainText(),
timeout=SHELL_TIMEOUT)
else:
# There is no exception, so the exception is None
qtbot.waitUntil(
lambda: 'None' in shell._control.toPlainText())
lambda: 'None' in shell._control.toPlainText(),
timeout=SHELL_TIMEOUT)


@pytest.mark.slow
Expand Down
14 changes: 10 additions & 4 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
from unicodedata import category
import logging
import functools
import os
import os.path as osp
import re
import sre_constants
import sys
import textwrap
from pkg_resources import parse_version

# Third party imports
from diff_match_patch import diff_match_patch
from IPython.core.inputtransformer2 import TransformerManager
from qtpy import QT_VERSION
from qtpy.compat import to_qvariant
from qtpy.QtCore import (QEvent, QRegExp, Qt, QTimer, QThread, QUrl, Signal,
Slot)
Expand Down Expand Up @@ -4573,11 +4576,14 @@ def _handle_keypress_event(self, event):
text = to_text_string(event.text())
if text:
# The next three lines are a workaround for a quirk of
# QTextEdit. See spyder-ide/spyder#12663 and
# QTextEdit on Linux with Qt < 5.15, MacOs and Windows.
# See spyder-ide/spyder#12663 and
# https://bugreports.qt.io/browse/QTBUG-35861
cursor = self.textCursor()
cursor.setPosition(cursor.position())
self.setTextCursor(cursor)
if (parse_version(QT_VERSION) < parse_version('5.15')
or os.name == 'nt' or sys.platform == 'darwin'):
cursor = self.textCursor()
cursor.setPosition(cursor.position())
self.setTextCursor(cursor)
self.sig_text_was_inserted.emit()

def keyPressEvent(self, event):
Expand Down
30 changes: 0 additions & 30 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,36 +1109,6 @@ def test_mpl_backend_change(ipyconsole, qtbot):
assert shell._control.toHtml().count('img src') == 1


@flaky(max_runs=10)
@pytest.mark.skipif(running_in_ci(), reason="Fails frequently in CI")
@pytest.mark.skipif(os.name == 'nt',
reason="Failing on Windows. In fact on Windows you can "
"copy with Ctrl + C i.e a KeyboardInterrupt isn't "
"triggered when doing Ctrl + C while debugging")
def test_ctrl_c_dbg(ipyconsole, qtbot):
"""
Test that Ctrl+C works while debugging
"""
shell = ipyconsole.get_current_shellwidget()

# Give focus to the widget that's going to receive clicks
control = ipyconsole.get_widget().get_focus_widget()
control.setFocus()

# Enter debugging mode
with qtbot.waitSignal(shell.executed):
shell.execute('%debug print()')

# Test Ctrl+C
qtbot.waitUntil(lambda: 'IPdb [1]: ' in control.toPlainText())
control.setFocus()
qtbot.keyClick(control, Qt.Key_C, modifier=Qt.ControlModifier)
qtbot.waitUntil(
lambda: 'For copying text while debugging, use Ctrl+Shift+C' in
control.toPlainText(), timeout=2000)

assert 'For copying text while debugging, use Ctrl+Shift+C' in control.toPlainText()


@flaky(max_runs=10)
@pytest.mark.skipif(os.name == 'nt', reason="It doesn't work on Windows")
Expand Down
6 changes: 6 additions & 0 deletions spyder/plugins/onlinehelp/tests/test_pydocgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Tests for pydocgui.py
"""
# Standard library imports
import os
import sys
from unittest.mock import MagicMock

Expand All @@ -18,6 +19,7 @@
from flaky import flaky

# Local imports
from spyder.config.base import running_in_ci
from spyder.plugins.onlinehelp.widgets import PydocBrowser


Expand Down Expand Up @@ -48,6 +50,10 @@ def pydocbrowser(qtbot):
NumpyVersion(np.__version__) < NumpyVersion('1.21.0')),
reason="Fails on Mac and older versions of Numpy"
)
@pytest.mark.skipif(
sys.platform.startswith('linux') or os.name == 'nt' and running_in_ci(),
reason="Stalls CI frequenly on Linux and Windows"
)
def test_get_pydoc(pydocbrowser, qtbot, lib):
"""
Go to the documentation by url.
Expand Down
2 changes: 2 additions & 0 deletions spyder/plugins/pylint/tests/test_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from unittest.mock import Mock, MagicMock

# Third party imports
from flaky import flaky
import pytest
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QApplication, QMainWindow
Expand Down Expand Up @@ -216,6 +217,7 @@ def test_pylint_widget_noproject(pylint_plugin, pylint_test_script, mocker,
assert pylint_data[1] is not None


@flaky(max_runs=3)
def test_pylint_widget_pylintrc(
pylint_plugin, pylint_test_script, pylintrc_files, mocker, qtbot):
"""Test that entire pylint widget gets results depending on pylintrc."""
Expand Down
13 changes: 9 additions & 4 deletions spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import sre_constants
import sys
import textwrap
from pkg_resources import parse_version

# Third party imports
from qtpy import QT_VERSION
from qtpy.QtCore import QPoint, QRegularExpression, Qt
from qtpy.QtGui import QCursor, QTextCursor, QTextDocument
from qtpy.QtWidgets import QApplication
Expand Down Expand Up @@ -1194,11 +1196,14 @@ def remove_selected_text(self):
"""Delete selected text."""
self.textCursor().removeSelectedText()
# The next three lines are a workaround for a quirk of
# QTextEdit. See spyder-ide/spyder#12663 and
# QTextEdit on Linux with Qt < 5.15, MacOs and Windows.
# See spyder-ide/spyder#12663 and
# https://bugreports.qt.io/browse/QTBUG-35861
cursor = self.textCursor()
cursor.setPosition(cursor.position())
self.setTextCursor(cursor)
if (parse_version(QT_VERSION) < parse_version('5.15')
or os.name == 'nt' or sys.platform == 'darwin'):
cursor = self.textCursor()
cursor.setPosition(cursor.position())
self.setTextCursor(cursor)

def replace(self, text, pattern=None):
"""Replace selected text by *text*.
Expand Down