How to handle modal dialog in pytest-qt without mocking the dialogHow do I check whether a file exists without exceptions?How to print without newline or space?How to get the filename without the extension from a path in Python?How to print the full traceback without halting the program?tkinter default button in a widgetPySide Qt Creator message dialog exitPyQt QDialog - returning a value and closing from dialogPyQt Multi Threading, Cannot create children for a parentCan I force matplotlib to block in a PyQt thread / process?Windows Automaton - InvokePattern blocking execution until everything has completed

The use of "I" and "we" used in the same sentence and other questions

Layout of complex table

Are Finite Automata Turing Complete?

How often can a PC check with passive perception during a combat turn?

How can Charles Proxy change settings without admin rights after first time?

Why does Darth Sidious need bodyguards?

How should I behave to assure my friends that I am not after their money?

MH370 blackbox - is it still possible to retrieve data from it?

In the Marvel universe, can a human have a baby with any non-human?

What is this particular type of chord progression, common in classical music, called?

Do equal angles necessarily mean a polygon is regular?

What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?

Is this one of the engines from the 9/11 aircraft?

Does squid ink pasta bleed?

How to perform Login Authentication at the client-side?

How to positively portray high and mighty characters?

Why cruise at 7000' in an A319?

What would Earth look like at night in medieval times?

Alphabet completion rate

Using symmetry of Riemann tensor to vanish components

C-152 carb heat on before landing in hot weather?

Every infinite linearly ordered set has two disjoint infinite subsets

What do you call the action of someone tackling a stronger person?

Is there a short way to compare many values mutually at same time without using multiple 'and's?



How to handle modal dialog in pytest-qt without mocking the dialog


How do I check whether a file exists without exceptions?How to print without newline or space?How to get the filename without the extension from a path in Python?How to print the full traceback without halting the program?tkinter default button in a widgetPySide Qt Creator message dialog exitPyQt QDialog - returning a value and closing from dialogPyQt Multi Threading, Cannot create children for a parentCan I force matplotlib to block in a PyQt thread / process?Windows Automaton - InvokePattern blocking execution until everything has completed






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am using pytest-qt to automate the testing of a PyQt GUI. The dialogs need to be handled as a part of the testing(dialogs should not be mocked).



For example, file dialog that comes after a button-click has to be handled. There are 2 problems



  1. After the button click command, the program control goes to the event handler and not to the next line where I can try to send mouseclick/keystrokes to the dialog.


  2. Since the QDialog is not added to the main widget, it is not being listed among the children of the main widget. So how to get the reference of the QDialog?


I tried multi-threading but that didn't work, later I found that QObjects are not thread-safe.



def test_filedialog(qtbot, window):
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)
print("After mouse click")
#This is where I need to get the reference of QDialog and handle it









share|improve this question






















  • try with: print(QtGui.QApplication.topLevelWidgets())

    – eyllanesc
    Mar 25 at 23:24











  • Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

    – Nagendra prasath
    Mar 26 at 8:50

















0















I am using pytest-qt to automate the testing of a PyQt GUI. The dialogs need to be handled as a part of the testing(dialogs should not be mocked).



For example, file dialog that comes after a button-click has to be handled. There are 2 problems



  1. After the button click command, the program control goes to the event handler and not to the next line where I can try to send mouseclick/keystrokes to the dialog.


  2. Since the QDialog is not added to the main widget, it is not being listed among the children of the main widget. So how to get the reference of the QDialog?


I tried multi-threading but that didn't work, later I found that QObjects are not thread-safe.



def test_filedialog(qtbot, window):
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)
print("After mouse click")
#This is where I need to get the reference of QDialog and handle it









share|improve this question






















  • try with: print(QtGui.QApplication.topLevelWidgets())

    – eyllanesc
    Mar 25 at 23:24











  • Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

    – Nagendra prasath
    Mar 26 at 8:50













0












0








0








I am using pytest-qt to automate the testing of a PyQt GUI. The dialogs need to be handled as a part of the testing(dialogs should not be mocked).



For example, file dialog that comes after a button-click has to be handled. There are 2 problems



  1. After the button click command, the program control goes to the event handler and not to the next line where I can try to send mouseclick/keystrokes to the dialog.


  2. Since the QDialog is not added to the main widget, it is not being listed among the children of the main widget. So how to get the reference of the QDialog?


I tried multi-threading but that didn't work, later I found that QObjects are not thread-safe.



def test_filedialog(qtbot, window):
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)
print("After mouse click")
#This is where I need to get the reference of QDialog and handle it









share|improve this question














I am using pytest-qt to automate the testing of a PyQt GUI. The dialogs need to be handled as a part of the testing(dialogs should not be mocked).



For example, file dialog that comes after a button-click has to be handled. There are 2 problems



  1. After the button click command, the program control goes to the event handler and not to the next line where I can try to send mouseclick/keystrokes to the dialog.


  2. Since the QDialog is not added to the main widget, it is not being listed among the children of the main widget. So how to get the reference of the QDialog?


I tried multi-threading but that didn't work, later I found that QObjects are not thread-safe.



def test_filedialog(qtbot, window):
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)
print("After mouse click")
#This is where I need to get the reference of QDialog and handle it






python pyqt4 ui-automation black-box-testing pytest-qt






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 11:16









Nagendra prasathNagendra prasath

13 bronze badges




13 bronze badges












  • try with: print(QtGui.QApplication.topLevelWidgets())

    – eyllanesc
    Mar 25 at 23:24











  • Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

    – Nagendra prasath
    Mar 26 at 8:50

















  • try with: print(QtGui.QApplication.topLevelWidgets())

    – eyllanesc
    Mar 25 at 23:24











  • Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

    – Nagendra prasath
    Mar 26 at 8:50
















try with: print(QtGui.QApplication.topLevelWidgets())

– eyllanesc
Mar 25 at 23:24





try with: print(QtGui.QApplication.topLevelWidgets())

– eyllanesc
Mar 25 at 23:24













Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

– Nagendra prasath
Mar 26 at 8:50





Thanks, @eyllanesc I can try that for getting the dialog reference. But I need to solve the first issue to try this.

– Nagendra prasath
Mar 26 at 8:50












1 Answer
1






active

oldest

votes


















0














It can be done using QTimer.



def test_filedialog(qtbot, window):
def handle_dialog():
# get a reference to the dialog and handle it here
QTimer.singleShot(500, handle_dialog)
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)


Refer this link for more details






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336575%2fhow-to-handle-modal-dialog-in-pytest-qt-without-mocking-the-dialog%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It can be done using QTimer.



    def test_filedialog(qtbot, window):
    def handle_dialog():
    # get a reference to the dialog and handle it here
    QTimer.singleShot(500, handle_dialog)
    qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)


    Refer this link for more details






    share|improve this answer



























      0














      It can be done using QTimer.



      def test_filedialog(qtbot, window):
      def handle_dialog():
      # get a reference to the dialog and handle it here
      QTimer.singleShot(500, handle_dialog)
      qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)


      Refer this link for more details






      share|improve this answer

























        0












        0








        0







        It can be done using QTimer.



        def test_filedialog(qtbot, window):
        def handle_dialog():
        # get a reference to the dialog and handle it here
        QTimer.singleShot(500, handle_dialog)
        qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)


        Refer this link for more details






        share|improve this answer













        It can be done using QTimer.



        def test_filedialog(qtbot, window):
        def handle_dialog():
        # get a reference to the dialog and handle it here
        QTimer.singleShot(500, handle_dialog)
        qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)


        Refer this link for more details







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 16:27









        Nagendra prasathNagendra prasath

        13 bronze badges




        13 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55336575%2fhow-to-handle-modal-dialog-in-pytest-qt-without-mocking-the-dialog%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript