Showing results for 
Search instead for 
Did you mean: 

PyQt5 import for testing QT only works on the first test run and not on subsequent test runs

Senior Member

PyQt5 import for testing QT only works on the first test run and not on subsequent test runs

A quick summary of the issue:
I'm testing a QT desktop application and some of the Tree control methods require a Qt object as a parameter to use the method (object of QPoint type). QPoint is not built into TestComplete as far as I can tell, so I'm trying to use PyQt5 site-package libraries (same version of python as my Test Complete isntall - Python 3.6 X64) to generate the appropriate object. I've tried a couple of different methods of importing external libraries and I'm using the recommended suggestion of putting the site packages in the Test Complete python libraries folder. I created a python test script to see if I can create the required QPoint object before using in my test scripts.
1) It works the first time I run the script
2) On subsequent runs of the script it doesn't' seem to load the libraries correctly but it generates a different error each time. If I then shut test complete and reopen, it will again work the first time but not subsequent times
3) The same code works perfectly fine in a local system interpreter.

It seems that Test Complete is doing something strange with the library import and is possibly not correctly unloading the library after the test script has finished. Any suggestions on either A) how to select QTreeView nodes (I've been advised that the indexAt method is required) or B) how to get the system to process the PyQt5 import would be greatly  appreaciated.


Longer explanation with more information:

I'm testing a QT desktop application and I'm getting stuck when trying to navigate the QTTreeView widgets. I can't select or open any of the tree nodes with the available methods. When I looked into the QT documentation for this QT object (QtreeView class)  and after speaking to our developers, apparently I need to use the indexAt () method to select the node by grid coordinates because the tree is an abstracted view of another object somewhere else.  In order to use the QTreeView_indexAt() method that the tree view returns in Testcomplete’s object browser I need to submit the coorindates as a QPoint object into the parameter.



TestComplete does not have the QPoint function built in that I can find. So initially I pulled down PyQt5 into my system python installation (which I matched to the python 3.6 version in test complete) and tried to reference it from the site packages there as described by a number of posts in this forum.
e.g. in a script I added the following code to test if it would work,  then I just ran the main function.





Import os
from os import sys
sys.path.insert(0, 'C:\\Python\\Python36\\Lib\\site-packages')
import PyQt5.QtCore

def main():
    qpoint_obj = PyQt5.QtCore.QPoint(3,5)





This didn’t seem to work because it was complaining about being unable to locate PyQt5.sip when importing QtCore, even though it’s in the path.
Also the same code works fine if I run the same code from the IDLE interpreter that comes with system installation.
(I also tried different import combinations with the same effect)

import os
from os import sys

sys.path.insert(0, 'C:\\Python\\Python36\\Lib\\site-packages') from PyQt5.QtCore import QPoint


Next, I tried the other suggestion when using external packages and copying the entire PyQt5 package to the Test complete installation directory





C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\Extensions\Python\Python36\Lib





So now the PyQt5 should be within the TestComplete python path.

Interestingly this seems to work on the first run of the main function, but then subsequently fails when I try to run it again. After until I close and reopen Test Complete, it again works for the first run but not again after, until I close again. I updated my script to the following to try diagnose if it was a problem with the loading of the imported PyQt5 modules. I created function to check if PyQt5 was being imported and to log it if it was not




import os
from os import sys
# sys.path.insert(0, 'C:\\Python\\Python36\\Lib\\site-packages')
#import importlib
import PyQt5.QtCore

def main():
  #import PyQt5.QtCore
  Log.Message("Python version: " + str(sys.version))
  qpoint_obj = PyQt5.QtCore.QPoint(3,5)

def check_if_module_imported(module_name_str):
	if module_name_str not in sys.modules:
		Log.Message(module_name_str + " Module not imported")
		Log.Message(module_name_str + " Module imported")




On the first attempt after re-opening Test Complete it works. On each subsequent attempt after that I get an error to do with the PyQt5 import, but the error changes each time I run it.


Attempt run 2 and 3:

Attempt 4:


Attempt 6:

I also tried placing Runner.Stop() at the end of my main function, but this did not resolve the issue for subsequent runs either
Any ideas on how to resolve this?

Community Hero

I'd contact Support directly.  Here's the link:

Community Manager

I see that the investigation is ongoing in case 00447869. It would be great if you shared the final results of the investigation in this thread, as well @nhucker ! This info could help people solve a similar issue in the future🙂

Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Get properties of a web page element

See replies!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file


How to execute remote test and obtain results via Test Runner REST API

Top Kudoed Authors