[Python] Issue: Tests Pass in Run Mode but Fail in Debug Mode with Qt (PySide6 - Python)

Discussão em 'Python' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I’m encountering a strange issue with my unit tests involving a Qt-based user interface. All my tests work perfectly in Run mode, but as soon as I switch to Debug mode and set a breakpoint anywhere in my code, the tests start failing.

    It seems the problem is related to the Qt interface "freezing" when a breakpoint is hit, and it never "unfreezes," preventing the tests from progressing.

    Here’s a snippet of the problematic code:

    def click_next_from_creation_plg(ctrl: Controller, qt_bot: QtBot, expected_res: bool):
    """
    Click on next button from plugin creation panel and check if it's active

    :param ctrl: Application controller
    :param qt_bot: (QtBot) qt test fixture instance
    :param expected_res: expected result on click, true if the button work, false else it doesn't work
    :return: None
    """
    current_page = ctrl.gui.stackedWidget.currentIndex()
    if ctrl.main_window is not None and ctrl.main_window.isVisible():
    if expected_res:
    QTest.mouseClick(ctrl.create_panel.gui.button_next, Qt.MouseButton.LeftButton)
    qt_bot.waitUntil(lambda: ctrl.gui.stackedWidget.currentIndex() != current_page, timeout=WAITING_QTBOT)
    assert current_page != ctrl.gui.stackedWidget.currentIndex(), ("The current page should change when "
    "the next button is clicked.")
    else:
    with qt_bot.assertNotEmitted(ctrl.create_panel.nextClicked):
    QTest.mouseClick(ctrl.create_panel.gui.button_next, Qt.MouseButton.LeftButton)
    assert current_page == ctrl.gui.stackedWidget.currentIndex(), ("The current page should not change "
    "when the next button is clicked but "
    "is not functional.")

    assert ctrl.gui.button_next.isEnabled() is expected_res, ("The next button's enabled state does not match the "
    "expected result.")


    And this is the error message :

    def click_next_from_creation_plg(ctrl: Controller, qt_bot: QtBot, expected_res: bool):
    """
    Click on next button from plugin creation panel and check if it's active

    :param ctrl: Application controller
    :param qt_bot: (QtBot) qt test fixture instance
    :param expected_res: expected result on click, true if the button work, false else it doesn't work
    :return: None
    """
    current_page = ctrl.gui.stackedWidget.currentIndex()
    if ctrl.main_window is not None and ctrl.main_window.isVisible():
    if expected_res:
    QTest.mouseClick(ctrl.create_panel.gui.button_next, Qt.MouseButton.LeftButton)
    > qt_bot.waitUntil(lambda: ctrl.gui.stackedWidget.currentIndex() != current_page, timeout=WAITING_QTBOT)
    E pytestqt.exceptions.TimeoutError: waitUntil timed out in 5000 milliseconds

    tools.py:164: TimeoutError


    Thanks in advance for your help!

    Continue reading...

Compartilhe esta Página