From 14f517637a283588963a804484a2343a5c5164d1 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 9 Feb 2017 20:29:10 -0500 Subject: [PATCH 1/6] Testing: Correctly stop pytest's on error failure This is needed now after adding tests for the main window --- runtests.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/runtests.py b/runtests.py index fa751a13128..1147a8b2067 100644 --- a/runtests.py +++ b/runtests.py @@ -10,7 +10,6 @@ # Standard library imports import os -import sys # Third party imports import qtpy # to ensure that Qt4 uses API v2 @@ -27,7 +26,13 @@ def main(): """ errno = pytest.main(['-x', 'spyder', '-v', '-rw', '--durations=10', '--cov=spyder', '--cov-report=term-missing']) - sys.exit(errno) + + # sys.exit doesn't work here because some things could be running + # in the background (e.g. closing the main window) when this point + # is reached. And if that's the case, sys.exit does't stop the + # script (as you would expected). + if errno != 0: + raise SystemExit(errno) if __name__ == '__main__': main() From cf40af345662806acc90d99b3e497a035d82b821 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 9 Feb 2017 20:44:50 -0500 Subject: [PATCH 2/6] Testing: Increase time for the IPython console to be ready in main windows tests --- spyder/app/tests/test_mainwindow.py | 35 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 635fab6bd6a..6c5fc136855 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -25,8 +25,17 @@ #============================================================================== # Constants #============================================================================== +# Location of this file LOCATION = osp.realpath(osp.join(os.getcwd(), osp.dirname(__file__))) +# Time to wait until the IPython console is ready to receive input +# (in miliseconds) +SHELL_TIMEOUT = 30000 + +# Time to wait for the IPython console to evaluate something (in +# miliseconds) +EVAL_TIMEOUT = 1500 + #============================================================================== # Utility functions @@ -46,7 +55,7 @@ def open_file_in_editor(main_window, fname, directory=None): def reset_run_code(qtbot, shell, code_editor, nsb): """Reset state after a run code test""" shell.execute('%reset -f') - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=EVAL_TIMEOUT) code_editor.setFocus() qtbot.keyClick(code_editor, Qt.Key_Home, modifier=Qt.ControlModifier) @@ -70,7 +79,7 @@ def test_run_code(main_window, qtbot): # ---- Setup ---- # Wait until the window is fully up shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000) + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) # Load test file main_window.editor.load(osp.join(LOCATION, 'script.py')) @@ -87,7 +96,7 @@ def test_run_code(main_window, qtbot): qtbot.keyClick(code_editor, Qt.Key_F5) # Wait until all objects have appeared in the variable explorer - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT) # Verify result assert shell.get_value('a') == 10 @@ -103,7 +112,7 @@ def test_run_code(main_window, qtbot): qtbot.wait(100) # Wait until all objects have appeared in the variable explorer - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT) # Verify result assert shell.get_value('a') == 10 @@ -119,7 +128,7 @@ def test_run_code(main_window, qtbot): qtbot.wait(100) # Wait until all objects have appeared in the variable explorer - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 3, timeout=EVAL_TIMEOUT) # Verify result assert shell.get_value('a') == 10 @@ -133,7 +142,7 @@ def test_run_code(main_window, qtbot): qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ControlModifier) # Wait until the object has appeared in the variable explorer - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 1, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 1, timeout=EVAL_TIMEOUT) # Verify result assert shell.get_value('a') == 10 @@ -156,7 +165,7 @@ def test_open_files_in_new_editor_window(main_window, qtbot): """ # Wait until the window is fully up shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000) + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) # Set a timer to manipulate the open dialog while it's running QTimer.singleShot(2000, lambda: open_file_in_editor(main_window, @@ -180,7 +189,7 @@ def test_maximize_minimize_plugins(main_window, qtbot): """Test that the maximize button is working correctly.""" # Wait until the window is fully up shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000) + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) # Set focus to the Editor main_window.editor.get_focus_widget().setFocus() @@ -211,12 +220,12 @@ def test_issue_4066(main_window, qtbot): """ # Create the object shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000) + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) shell.execute('myobj = [1, 2, 3]') # Open editor associated with that object and get a reference to it nsb = main_window.variableexplorer.get_focus_widget() - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=EVAL_TIMEOUT) nsb.editor.setFocus() nsb.editor.edit_item() obj_editor_id = list(nsb.editor.delegate._editors.keys())[0] @@ -225,7 +234,7 @@ def test_issue_4066(main_window, qtbot): # Move to the IPython console and delete that object main_window.ipyconsole.get_focus_widget().setFocus() shell.execute('del myobj') - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() == 0, timeout=EVAL_TIMEOUT) # Close editor ok_widget = obj_editor.bbox.button(obj_editor.bbox.Ok) @@ -243,13 +252,13 @@ def test_varexp_edit_inline(main_window, qtbot): """ # Create object shell = main_window.ipyconsole.get_current_shellwidget() - qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=15000) + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) shell.execute('a = 10') # Edit object main_window.variableexplorer.visibility_changed(True) nsb = main_window.variableexplorer.get_focus_widget() - qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=1500) + qtbot.waitUntil(lambda: nsb.editor.model.rowCount() > 0, timeout=EVAL_TIMEOUT) nsb.editor.setFocus() nsb.editor.edit_item() From 94fb198872796aba799bd02d6f84791bf4eaad16 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 9 Feb 2017 22:56:23 -0500 Subject: [PATCH 3/6] Testing: Skip two more main window tests on Windows because they usually fail --- spyder/app/tests/test_mainwindow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 6c5fc136855..95b497ed450 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -209,6 +209,7 @@ def test_maximize_minimize_plugins(main_window, qtbot): main_window.close() +@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows") def test_issue_4066(main_window, qtbot): """ Test for a segfault when these steps are followed: @@ -241,6 +242,7 @@ def test_issue_4066(main_window, qtbot): qtbot.mouseClick(ok_widget, Qt.LeftButton) +@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows") def test_varexp_edit_inline(main_window, qtbot): """ Test for errors when editing inline values in the Variable Explorer From 35f2b47d4e6de4ed8eed8589f630ef56b61d9acd Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 9 Feb 2017 23:13:00 -0500 Subject: [PATCH 4/6] Main Window: Fix error that sometimes appear when running pytest's --- spyder/app/mainwindow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index ba6aa056bf1..ab554d02aaa 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -1129,7 +1129,10 @@ def add_ipm_action(text, path): # Menu about to show for child in self.menuBar().children(): if isinstance(child, QMenu): - child.aboutToShow.connect(self.update_edit_menu) + try: + child.aboutToShow.connect(self.update_edit_menu) + except TypeError: + pass self.debug_print("*** End of MainWindow setup ***") self.is_starting_up = False From b43926dc15cc97aa26ed879b2de534326e855ce3 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 10 Feb 2017 07:15:13 -0500 Subject: [PATCH 5/6] Testing: Improve some comments --- continuous_integration/appveyor/run_test.bat | 12 +++--------- spyder/app/tests/test_mainwindow.py | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/continuous_integration/appveyor/run_test.bat b/continuous_integration/appveyor/run_test.bat index e5aec45ac3f..730e68fea07 100644 --- a/continuous_integration/appveyor/run_test.bat +++ b/continuous_integration/appveyor/run_test.bat @@ -17,12 +17,6 @@ conda install -q -y --use-local spyder-dev :: Install extra packages conda install -q -y %EXTRA_PACKAGES% -:: Test that the app starts correctly -echo ------- Testing the app --------- -echo. -echo %time% -:: skipping spyder || exit 1 -echo Success! -echo %time% -echo. -echo --------------------------------- +:: NOTE: We don't run Spyder here because it times out +:: most of the time. However, the whole window is now +:: run as part of our pytest's. diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index 95b497ed450..bd04e5cd75d 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -155,7 +155,7 @@ def test_run_code(main_window, qtbot): main_window.close() -@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows") +@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows") def test_open_files_in_new_editor_window(main_window, qtbot): """ This tests that opening files in a new editor window @@ -209,7 +209,7 @@ def test_maximize_minimize_plugins(main_window, qtbot): main_window.close() -@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows") +@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows") def test_issue_4066(main_window, qtbot): """ Test for a segfault when these steps are followed: @@ -242,7 +242,7 @@ def test_issue_4066(main_window, qtbot): qtbot.mouseClick(ok_widget, Qt.LeftButton) -@pytest.mark.skipif(os.name == 'nt', reason="It's timing out sometimes on Windows") +@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows") def test_varexp_edit_inline(main_window, qtbot): """ Test for errors when editing inline values in the Variable Explorer From 1292e21ddc3cb6eeccf66661cdbf1ab2f9133093 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 10 Feb 2017 07:24:16 -0500 Subject: [PATCH 6/6] Testing: Increase EVAL_TIMEOUT for main window tests Hopefully this helps with tests on Windows --- spyder/app/tests/test_mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index bd04e5cd75d..abc60c22087 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -34,7 +34,7 @@ # Time to wait for the IPython console to evaluate something (in # miliseconds) -EVAL_TIMEOUT = 1500 +EVAL_TIMEOUT = 3000 #==============================================================================