Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:15:44+00:00 2026-06-09T21:15:44+00:00

I’m building a PySide 1.1.0-based application, and have been looking for good examples to

  • 0

I’m building a PySide 1.1.0-based application, and have been looking for good examples to look at for unit and functional testing my application. I want to be able to do functional testing of the UI (simulating clicks, key presses, etc), unit testing of UI slots that alter the layout of the UI (presumably using a partially-mocked sender and receiver), as well as unit testing of code that involves widgets, but without requiring any windows to be rendered.

As one example, I dynamically create submenus of one menu in the menubar when an item is added to a model (QAbstractItemModel-derived object) that provides data to a QTreeView. The model and submenu must stay in sync, so I want to be able to write a unit test that submits data to the controller that manages the model and submenu, and asserts that both the model and submenu were properly updated.

I would prefer to NOT have to set up a QApplication in my test code if I can avoid it. I also would like to not have to display any windows when I only care about validating data structures in widgets, not their visualization.

I can’t find anything of suitable value at http://www.pyside.org or in my Google searches. Does anyone have any experience or know of good sample code that I should look at?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:15:46+00:00Added an answer on June 9, 2026 at 9:15 pm

    I’ve been playing around a bit now with unit-testing pyside code and came to the conclusion that combining python’s unittest module with qt’s QTest module works pretty good.

    You will have to have a QApplication object instantiated, but you do not need to run its exec_ method, because you don’t need the event loop to be running.

    Here is an example on how I test if a QCheckBox in a dialog does what it is supposed to do:

    class Test_PwsAddEntryDialog(TestCase):
        """Tests the class PwsAddEntryDialog."""
    
        def test_password_strength_checking_works(self):
            """Tests if password strength checking works, if the corresponding check
            box is checked.
            """
            d = PwsAddEntryDialog()
            # test default of internal flag
            self.assertFalse(d.testPasswordStrength)
            # type something
            QTest.keyClicks(d.editSecret, "weak", 0, 10)
            # make sure that entered text is not treated as a password
            self.assertEqual(d.labelPasswordStrength.text(), "")
            # click 'is password' checkbox
            QTest.mouseClick(d.checkIsPassword, Qt.LeftButton)
            # test internal flag changed
            self.assertTrue(d.testPasswordStrength)
            # test that label now contains a warning
            self.assertTrue(d.labelPasswordStrength.text().find("too short") > 0)
            # click checkbox again
            QTest.mouseClick(d.checkIsPassword, Qt.LeftButton)
            # check that internal flag once again changed
            self.assertFalse(d.testPasswordStrength)
            # make sure warning disappeared again
            self.assertEqual(d.labelPasswordStrength.text(), "")
    

    This completely works off-screen, involves clicking widgets and typing text in a QLineEdit.

    Here is how I test a (rather simple) QAbstractListModel:

    class Test_SectionListModel(TestCase):
        """Tests the class SectionListModel."""
    
        def test_model_works_as_expected(self):
            """Tests if the expected rows are generated from a sample pws file
            content.
            """
            model = SectionListModel(SAMPLE_PASSWORDS_DICT)
            l = len(SAMPLE_PASSWORDS_DICT)
            self.assertEqual(model.rowCount(None), l)
            i = 0
            for section in SAMPLE_PASSWORDS_DICT.iterkeys():
                self.assertEqual(model.data(model.index(i)), section)
                i += 1
    

    I hope this helps a littlebit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.