My query is if I can write scripts inside TestComplete using unittest? (Don`t get me wrong. Not import unittest/pytest test suite. WRITE tests in Scripts 'directory')

As per TC (TestComplete) documentation it is possible to run unittest scripts --> https://support.smartbear.com/testcomplete/docs/working-with/integration/unit-test-frameworks/pyunit.html

However all examples explicitly involve UnitTest module. And I want to use Scripts module.

Simply put my intent is to automate desktop app using PageObjectModel pattern. I am aware that there are python libraries like PyAutoGUI but thing is application under test is a nightmarish mess**. It is easier to handle it with help of TC since I gave it a try with:

  • PyAutoGui (could not click element due to level in duplicated object tree),
  • Appium driver and Java which got stuck for hours 'trying' to click a single element

**(AUT is mixing QT, java swing, java fx and browser locators (and propably some win wpf items too so easier to let TC handle it)

My idea is to:

record some actions on the desktop, convert them to a script, pack them in classes respectively per window and/ or widget (like internal webbrowser), Use unittest test classes (inherit from unittest.TestCase) to run assertions in clean manner. => here is the problem.

Writing in TC things like that won`t work:

import unittest

class SimpleTest(unittest.TestCase):

    def foo(self):
        a = 'abc'
        b = 'abc'
        self.assertEqual(a, b)

    def bar(self):
        a = 'abc'
        b = 'def'
        self.assertEqual(a, b)  # I would be expecting to /
                                # TC throw an assertion exception here /
                                # but all I got is 'passed' in log

#if __name__='__main__' won`t work in TC
#if __name__ == '__main__': 
#    unittest.main() 

If I write that way it worked as "intended":

def foo():
    a = 'abc'
    b = 'abc'
    assert a == b

def bar():
    a = 'abc'
    b = 'def'
    assert a == b   #BOOM! FAILED

1 Answer 1


TestComplete supports running unittest scripts, as described in the documentation you mentioned. It also has a built-in scripting language, JScript, and supports several other scripting languages, including Python.

If you want to use unittest in your TestComplete scripts, you can write your test classes in Python, and include them in your TestComplete project. You will need to use the unittest framework provided by Python, just as you would in a standalone Python script.

It seems like you are encountering a problem with using unittest in TestComplete, as the assertions in your unittest class are not failing as expected. This may be because TestComplete's scripting environment does not properly interact with the unittest framework. To resolve this issue, you may want to try using a different testing framework, such as pytest, or use the built-in JScript or Python scripting capabilities of TestComplete to write your tests.

  • Pytest didnt worked out. Neither did Unittest. Only python built in assertions work which might force my hand to either go with "purist" approach or do some lovely/ugly wrapper methods around it... I didn`t have any bigger hopes for that either way ;)
    – karl5252
    Apr 15 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.