Forum Discussion

DKumar04's avatar
DKumar04
Contributor
6 years ago

How testcomplete works with scripts not being written inside the class?

My question is if I have written my scripts using python. Let consider the below example

# example1.py

def test():

   print "hello world"

# example2.py

class sampletest:

      def test():

          print "hello world"

In the above examples, one being wriiten without class and other within class. I was surprised how testcomplete works with first example .

  • tristaanogre's avatar
    tristaanogre
    6 years ago

    Keep in mind... this is Python SCRIPT, not full Python.  Not everything needs to have a class to be able to execute.  You can use classes, but they are not required for execution of functions.

  • IStaroverov's avatar
    IStaroverov
    SmartBear Alumni (Retired)

    This behavior is similar to a launching this code(e.g. in Python IDLE):

    def test():
      print "hello world"
    test()

    but if you want to print the message in TestComplete, need to use: Log.Message("hello world")

    • DKumar04's avatar
      DKumar04
      Contributor

      but my question is not about printing it's about how test complete works when there is no class but only routines inside .py script file?

      • TanyaYatskovska's avatar
        TanyaYatskovska
        SmartBear Alumni (Retired)

        As far as I understand it works without the class. Do you have any errors?