[PyQt] Testing a standalone dialog widget

Jones, Bryan bjones at ece.msstate.edu
Mon Jan 12 21:54:31 GMT 2015


All,

Thanks for the comments, particuarly the reminder on the difficult of
combining unit tests in Python with the QTest interface. What works for me
when testing: make the QApplication instance a module-level variable. Yes,
this isn't the right way to do things for traditional application...but it
works fine when testing for me. I'd be interested to hear others' comments.

Specifically, referring to the test code:
http://johnnado.com/pyqt-qtest-example/ for docs,
https://bitbucket.org/jmcgeheeiv/pyqttestexample for the code

Change MargaritaMixerTest.py starting at line 39 to be...

# This is new
app = QApplication(sys.argv)

class MargaritaMixerTest(unittest.TestCase):
    '''Test the margarita mixer GUI'''
    def setUp(self):
        '''Create the GUI'''
        # Commented out: self.app = QApplication(sys.argv)
        self.form = MargaritaMixer.MargaritaMixer()

..the rest of the code is the same...

Bryan



On Tue, Dec 30, 2014 at 2:03 AM, Antonio Valentino <
antonio.valentino at tiscali.it> wrote:

> Hi David, hi Andre,
>
> Il 29/12/2014 23:51, Andre Roberge ha scritto:
> > On Mon, Dec 29, 2014 at 6:41 PM, David Cortesi <davecortesi at gmail.com>
> > wrote:
> >
> >>
> >> From: Antonio Valentino <antonio.valentino at tiscali.it>
> >>> I'm very interested in this topic so if anyone has some useful pointers
> >>> to material about unittesting of PyQt based GUI applications please
> share.
> >>>
> >>
> >> I have found Sikuli (http://www.sikuli.org/) useful for this. You can
> set
> >> up quite complex scenarios and validate the GUI response.
> >>
> >> A Sikuli script is a Python script. Basically you start one off with
> >>
> >> subprocess.Popen(['/usr/local/bin/python', 'path-to-test-driver.py'])
> >>
> >> and then continue with Sikuli statements to click, or type, or look for
> >> specific visual items in the UI presented by the test-driver.py
> execution.
> >> There is an interactive tool for dragging to select particular bits of
> UI,
> >> a menu or a dialog or whatever, and say "expect that here".
> >>
> >
> > In my original post on this topic, I mentioned that I was using pyautogui
> > which works (I thought) similarly to Sikuli.  The problem with this
> > approach is that one pretty much has to leave the monitor alone while the
> > tests are run and it might be difficult to set thing up with automated
> > testing providers (like https://travis-ci.org/).   Since PyQt includes
> > QTest, I was thinking that there had to be many people using it and that
> > there should be some relatively easy/standard ways of doing unittesting
> > with QTest.
>
> I totally agree
>
> > However... you do write that you have found Sikuli useful. Is there some
> > relatively straightforward way to run tests quickly with Sikuli so that
> it
> > does not interrupt the workflow significantly (which I found pyautogui
> was
> > doing.)
> >
> > André
> >
>
> Thanks, I will give a look to both Sikuli and pyautogui.
>
> best ragards
>
> --
> Antonio Valentino
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150112/a09f7573/attachment-0001.html>


More information about the PyQt mailing list