From c3b9e83ae6c8718c1a59d883a4d1c7b35218a499 Mon Sep 17 00:00:00 2001 From: Ludovico Bianchi Date: Tue, 21 Jun 2022 16:47:04 -0500 Subject: [PATCH] Revert "Try if by any chance changing fixture order and lifetime helps w/ crashes" This reverts commit 9ccafe0827c9baf6e9a6e6f08f8f45830bb56c21. --- foqus_lib/gui/tests/conftest.py | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/foqus_lib/gui/tests/conftest.py b/foqus_lib/gui/tests/conftest.py index 29c240d1c..4e32d9004 100644 --- a/foqus_lib/gui/tests/conftest.py +++ b/foqus_lib/gui/tests/conftest.py @@ -37,6 +37,18 @@ def qtbot_params(request): } +@pytest.fixture(scope="class") +def qtbot(request, qapp, qtbot_params) -> pytest_qt_extras.QtBot: + if sys.version_info < (3, 7): + pytest.skip("GUI tests are not available for Python 3.6 or lower") + _qtbot = pytest_qt_extras.QtBot(request, **qtbot_params) + with capture_exceptions() as exceptions: + yield _qtbot + if exceptions: + pytest.fail(format_captured_exceptions(exceptions)) + # _qtbot.cleanup() + + @pytest.fixture(scope="session") def main_window_params(request): cfg = request.config @@ -48,8 +60,8 @@ def main_window_params(request): } -@pytest.fixture(scope="module") -def main_window(foqus_session, main_window_params): +@pytest.yield_fixture(scope="class") +def main_window(foqus_session, qtbot, main_window_params): from foqus_lib import foqus foqus.guiImport(mpl_backend="AGG") @@ -73,6 +85,7 @@ def main_window(foqus_session, main_window_params): main_win.app = QtWidgets.QApplication.instance() print(f"main_win.app={main_win.app}") # qtbot.add_widget(main_win) + qtbot.waitForWindowShown(main_win) print(f"main_win.app.activeWindow()={main_win.app.activeWindow()}") yield main_win @@ -83,25 +96,11 @@ def handle_closing_prompt(w: QtWidgets.QMessageBox): handle_closing_prompt ): main_win.close() - QtWidgets.QApplication.processEvents() - - -@pytest.fixture(scope="class") -def qtbot(request, qapp, qtbot_params, main_window) -> pytest_qt_extras.QtBot: - if sys.version_info < (3, 7): - pytest.skip("GUI tests are not available for Python 3.6 or lower") - _qtbot = pytest_qt_extras.QtBot(request, **qtbot_params) - _qtbot.waitForWindowShown(main_window) - with capture_exceptions() as exceptions: - yield _qtbot - if exceptions: - pytest.fail(format_captured_exceptions(exceptions)) - _qtbot.cleanup() - QtWidgets.QApplication.processEvents() + qtbot.cleanup() @pytest.fixture(scope="class") -def uq_setup_view(main_window, flowsheet_session_file): +def uq_setup_view(main_window, flowsheet_session_file, qtbot): main_window.loadSessionFile(flowsheet_session_file, saveCurrent=False) main_window.uqSetupAction.trigger() return main_window.uqSetupFrame