Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Can I unittest Qt elements?

Can I unittest Qt elements?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 800 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buhtz
    wrote on last edited by
    #1

    Is there a way or does Qt offer features to unittest some elements?

    An example would be a simple dialog with a textedit field and an OK and Cancel button. A config variable would change its value based on the input the user makes in that dialog and pushing OK.

    Can I test that isolated without having an X-server running and with simulating user input?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Yes and yes.

      You can use pytest-qt to write your tests and use the offscreen QPA to run your tests without any screen.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Yes and yes.

        You can use pytest-qt to write your tests and use the offscreen QPA to run your tests without any screen.

        B Offline
        B Offline
        buhtz
        wrote on last edited by
        #3

        @SGaist said in Can I unittest Qt elements?:

        You can use pytest-qt to write your tests and use the offscreen QPA to run your tests without any screen.

        Thanks for the hints. I found the pytest-qt docu. I wouldn't use pytest if I doesn't need to. I hope there is a solution for usual Python unittests. If not I think Qt would be a reason to dive deeper into pytest (which I already know but don't like to use).

        What is QPA?

        Do you have a tutorial or a public repo where I can see that in action?

        The Qt docu is not the best when it comes to real examples and Python code. I just checked the API-reference of QTest and QSpySignal. But there is C code in the examples. I don't know how to combine this with unittest.TestCase.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          From memory you can use classic Python unittests with pytest. Frankly, pytest-qt makes things really simple and easy for Qt related unit testing that you really should use it.

          Here you have the QPA (Qt Platform Abstraction) documentation.

          As for the examples, use the pytest-qt documentation. The examples from the Qt for Python documentation are translated automatically and this can leave some less than ideal result but this is being worked on.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • SGaistS SGaist

            From memory you can use classic Python unittests with pytest. Frankly, pytest-qt makes things really simple and easy for Qt related unit testing that you really should use it.

            Here you have the QPA (Qt Platform Abstraction) documentation.

            As for the examples, use the pytest-qt documentation. The examples from the Qt for Python documentation are translated automatically and this can leave some less than ideal result but this is being worked on.

            B Offline
            B Offline
            buhtz
            wrote on last edited by
            #5

            @SGaist said in Can I unittest Qt elements?:

            From memory you can use classic Python unittests with pytest.

            But I don't want to use pytest.

            Frankly, pytest-qt makes things really simple and easy for Qt related unit testing that you really should use it.

            "simple" is the problem. PyTest hide to much and has to much backroom automatics. I lose control when using PyTest.

            Here you have the QPA (Qt Platform Abstraction) documentation.

            Doesn't help. No python example code.

            As for the examples, use the pytest-qt documentation.

            Doesn't show me tests derived from unittest.TestCase.

            The examples from the Qt for Python documentation are translated automatically

            Yes I am aware of that problem.

            SGaistS 1 Reply Last reply
            0
            • B buhtz

              @SGaist said in Can I unittest Qt elements?:

              From memory you can use classic Python unittests with pytest.

              But I don't want to use pytest.

              Frankly, pytest-qt makes things really simple and easy for Qt related unit testing that you really should use it.

              "simple" is the problem. PyTest hide to much and has to much backroom automatics. I lose control when using PyTest.

              Here you have the QPA (Qt Platform Abstraction) documentation.

              Doesn't help. No python example code.

              As for the examples, use the pytest-qt documentation.

              Doesn't show me tests derived from unittest.TestCase.

              The examples from the Qt for Python documentation are translated automatically

              Yes I am aware of that problem.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @buhtz said in Can I unittest Qt elements?:

              @SGaist said in Can I unittest Qt elements?:

              From memory you can use classic Python unittests with pytest.

              But I don't want to use pytest.

              Up to you

              Frankly, pytest-qt makes things really simple and easy for Qt related unit testing that you really should use it.

              "simple" is the problem. PyTest hide to much and has to much backroom automatics. I lose control when using PyTest.

              What exactly are you losing ?

              Here you have the QPA (Qt Platform Abstraction) documentation.

              Doesn't help. No python example code.

              That was not the goal, it is just information about QPA. In your case, you need to set the QT_QPA_PLATFORM environment variable before calling the unit tests.

              As for the examples, use the pytest-qt documentation.

              Doesn't show me tests derived from unittest.TestCase.

              This stack overflow answer might give you a start.

              The examples from the Qt for Python documentation are translated automatically

              Yes I am aware of that problem.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved