Skip to content

Commit 5c45a9e

Browse files
authored
Merge pull request #4130 from ccordoba12/stop-tests-on-failure
PR: Correctly stop pytest's on failure
2 parents 26edaa4 + 1292e21 commit 5c45a9e

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

Diff for: continuous_integration/appveyor/run_test.bat

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ conda install -q -y --use-local spyder-dev
1717
:: Install extra packages
1818
conda install -q -y %EXTRA_PACKAGES%
1919

20-
:: Test that the app starts correctly
21-
echo ------- Testing the app ---------
22-
echo.
23-
echo %time%
24-
:: skipping spyder || exit 1
25-
echo Success!
26-
echo %time%
27-
echo.
28-
echo ---------------------------------
20+
:: NOTE: We don't run Spyder here because it times out
21+
:: most of the time. However, the whole window is now
22+
:: run as part of our pytest's.

Diff for: runtests.py

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

1111
# Standard library imports
1212
import os
13-
import sys
1413

1514
# Third party imports
1615
import qtpy # to ensure that Qt4 uses API v2
@@ -27,7 +26,13 @@ def main():
2726
"""
2827
errno = pytest.main(['-x', 'spyder', '-v', '-rw', '--durations=10',
2928
'--cov=spyder', '--cov-report=term-missing'])
30-
sys.exit(errno)
29+
30+
# sys.exit doesn't work here because some things could be running
31+
# in the background (e.g. closing the main window) when this point
32+
# is reached. And if that's the case, sys.exit does't stop the
33+
# script (as you would expected).
34+
if errno != 0:
35+
raise SystemExit(errno)
3136

3237
if __name__ == '__main__':
3338
main()

Diff for: spyder/app/mainwindow.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,10 @@ def add_ipm_action(text, path):
11291129
# Menu about to show
11301130
for child in self.menuBar().children():
11311131
if isinstance(child, QMenu):
1132-
child.aboutToShow.connect(self.update_edit_menu)
1132+
try:
1133+
child.aboutToShow.connect(self.update_edit_menu)
1134+
except TypeError:
1135+
pass
11331136

11341137
self.debug_print("*** End of MainWindow setup ***")
11351138
self.is_starting_up = False

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@
2525
#==============================================================================
2626
# Constants
2727
#==============================================================================
28+
# Location of this file
2829
LOCATION = osp.realpath(osp.join(os.getcwd(), osp.dirname(__file__)))
2930

31+
# Time to wait until the IPython console is ready to receive input
32+
# (in miliseconds)
33+
SHELL_TIMEOUT = 30000
34+
35+
# Time to wait for the IPython console to evaluate something (in
36+
# miliseconds)
37+
EVAL_TIMEOUT = 3000
38+
3039

3140
#==============================================================================
3241
# Utility functions
@@ -46,7 +55,7 @@ def open_file_in_editor(main_window, fname, directory=None):
4655
def reset_run_code(qtbot, shell, code_editor, nsb):
4756
"""Reset state after a run code test"""
4857
shell.execute('%reset -f')
49-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=1500)
58+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=EVAL_TIMEOUT)
5059
code_editor.setFocus()
5160
qtbot.keyClick(code_editor, Qt.Key_Home, modifier=Qt.ControlModifier)
5261

@@ -70,7 +79,7 @@ def test_run_code(main_window, qtbot):
7079
# ---- Setup ----
7180
# Wait until the window is fully up
7281
shell = main_window.ipyconsole.get_current_shellwidget()
73-
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000)
82+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
7483

7584
# Load test file
7685
main_window.editor.load(osp.join(LOCATION, 'script.py'))
@@ -87,7 +96,7 @@ def test_run_code(main_window, qtbot):
8796
qtbot.keyClick(code_editor, Qt.Key_F5)
8897

8998
# Wait until all objects have appeared in the variable explorer
90-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500)
99+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT)
91100

92101
# Verify result
93102
assert shell.get_value('a') == 10
@@ -103,7 +112,7 @@ def test_run_code(main_window, qtbot):
103112
qtbot.wait(100)
104113

105114
# Wait until all objects have appeared in the variable explorer
106-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500)
115+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT)
107116

108117
# Verify result
109118
assert shell.get_value('a') == 10
@@ -119,7 +128,7 @@ def test_run_code(main_window, qtbot):
119128
qtbot.wait(100)
120129

121130
# Wait until all objects have appeared in the variable explorer
122-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500)
131+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT)
123132

124133
# Verify result
125134
assert shell.get_value('a') == 10
@@ -133,7 +142,7 @@ def test_run_code(main_window, qtbot):
133142
qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ControlModifier)
134143

135144
# Wait until the object has appeared in the variable explorer
136-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 1, timeout=1500)
145+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 1, timeout=EVAL_TIMEOUT)
137146

138147
# Verify result
139148
assert shell.get_value('a') == 10
@@ -146,7 +155,7 @@ def test_run_code(main_window, qtbot):
146155
main_window.close()
147156

148157

149-
@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows")
158+
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
150159
def test_open_files_in_new_editor_window(main_window, qtbot):
151160
"""
152161
This tests that opening files in a new editor window
@@ -156,7 +165,7 @@ def test_open_files_in_new_editor_window(main_window, qtbot):
156165
"""
157166
# Wait until the window is fully up
158167
shell = main_window.ipyconsole.get_current_shellwidget()
159-
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000)
168+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
160169

161170
# Set a timer to manipulate the open dialog while it's running
162171
QTimer.singleShot(2000, lambda: open_file_in_editor(main_window,
@@ -180,7 +189,7 @@ def test_maximize_minimize_plugins(main_window, qtbot):
180189
"""Test that the maximize button is working correctly."""
181190
# Wait until the window is fully up
182191
shell = main_window.ipyconsole.get_current_shellwidget()
183-
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000)
192+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
184193

185194
# Set focus to the Editor
186195
main_window.editor.get_focus_widget().setFocus()
@@ -200,6 +209,7 @@ def test_maximize_minimize_plugins(main_window, qtbot):
200209
main_window.close()
201210

202211

212+
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
203213
def test_issue_4066(main_window, qtbot):
204214
"""
205215
Test for a segfault when these steps are followed:
@@ -211,12 +221,12 @@ def test_issue_4066(main_window, qtbot):
211221
"""
212222
# Create the object
213223
shell = main_window.ipyconsole.get_current_shellwidget()
214-
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000)
224+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
215225
shell.execute('myobj = [1, 2, 3]')
216226

217227
# Open editor associated with that object and get a reference to it
218228
nsb = main_window.variableexplorer.get_focus_widget()
219-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=1500)
229+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=EVAL_TIMEOUT)
220230
nsb.editor.setFocus()
221231
nsb.editor.edit_item()
222232
obj_editor_id = list(nsb.editor.delegate._editors.keys())[0]
@@ -225,13 +235,14 @@ def test_issue_4066(main_window, qtbot):
225235
# Move to the IPython console and delete that object
226236
main_window.ipyconsole.get_focus_widget().setFocus()
227237
shell.execute('del myobj')
228-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=1500)
238+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=EVAL_TIMEOUT)
229239

230240
# Close editor
231241
ok_widget = obj_editor.bbox.button(obj_editor.bbox.Ok)
232242
qtbot.mouseClick(ok_widget, Qt.LeftButton)
233243

234244

245+
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
235246
def test_varexp_edit_inline(main_window, qtbot):
236247
"""
237248
Test for errors when editing inline values in the Variable Explorer
@@ -243,13 +254,13 @@ def test_varexp_edit_inline(main_window, qtbot):
243254
"""
244255
# Create object
245256
shell = main_window.ipyconsole.get_current_shellwidget()
246-
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000)
257+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
247258
shell.execute('a = 10')
248259

249260
# Edit object
250261
main_window.variableexplorer.visibility_changed(True)
251262
nsb = main_window.variableexplorer.get_focus_widget()
252-
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=1500)
263+
qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=EVAL_TIMEOUT)
253264
nsb.editor.setFocus()
254265
nsb.editor.edit_item()
255266

0 commit comments

Comments
 (0)