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. Testing code with QNetworkAccessManager in it
Qt 6.11 is out! See what's new in the release blog

Testing code with QNetworkAccessManager in it

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 513 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.
  • Chris HennesC Offline
    Chris HennesC Offline
    Chris Hennes
    wrote on last edited by
    #1

    I've got a piece of code that uses a QNetworkAccessManager. The overall software has a unit test suite, and I'm working on adding some tests for the piece of code with the QNAM in it. Run the tests from the GUI, this is no problem. But we also provide a way to run the tests from the command line, where there is no event loop. You can probably see the problem! QNAM requires an event loop to do anything.

    I have never had to use a QEventLoop directly, I don't really understand how to go about it (or if it will even work for me in this case). I was hoping I could do something like:

    self.blocking_event_loop = QtCore.QEventLoop()
    timer = QtCore.QTimer(self.blocking_event_loop)
    timer.setInterval(0)
    timer.timeout.connect(self.__event_loop_processing)
    timer.start()
    self.blocking_event_loop.exec_()
    

    Can anyone point me in the right direction?

    Chris Hennes, Pioneer Library System

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

      Hi,

      You can either use QCoreApplication or if it's just a question of having no graphic server for your tests, then you can use the offscreen qpa plugin.

      And since you are using Python, did you consider using pytest-qt ? That should help you setting your tests,

      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
      • Chris HennesC Offline
        Chris HennesC Offline
        Chris Hennes
        wrote on last edited by
        #3

        Thanks for the input -- I was under the impression that QCoreApplication was a singleton. How can my test create and then destroy one (so it doesn't interfere with anything that any other tests might do)? I don't have any control over the test framework used, this is a tiny part of a much larger system. If it can't be tested that's not the end of the world, it's just not ideal.

        Chris Hennes, Pioneer Library System

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

          QApplication is a singleton as well.

          Would it be possible to know what is used for testing ?

          And also how you are doing your GUI testing ? Because, AFAIU, that part is already covered.

          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