Login | Register
My pages Projects Community openCollabNet

Discussions > users > Creating a base class

maxq
Discussion topic

Back to topic list

Creating a base class

Author hms_suprise
Full name john v hite
Date 2007-05-22 08:23:53 PDT
Message I have tried unsuccessfully to create a base class using a standard script.
I want to put all the functions I use most often in this base class. In th
file main.py below I have done nothing but change the import class to
baseClass and added a calle to logon. The first time I run it I get the
error:

NameError: validatorPkg

The second time I run it (after a baseClass class file is generated) I get
the error:

ImportError: cannot import name baseClass

I experimented with other jython scripts and have been able to do this. I
don't understand all that is going on with the first 8 lines of the standard
script and I suspect that this has something to do with it. I am guessing
that those lines are not executed when I try to import from the baseClass
file. I also tried moving those lines (except the if) inside the class to no
avail.

Ideas?

Thanks,

John
~~~~~~~~~~~~~~~~~~~~​~~~~~~~~~~~~~~~~~~~~​~~
File main.py
# Generated by MaxQ [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
from PyHttpTestCase import PyHttpTestCase
from com.bitmechanic.maxq import Config
global validatorPkg
if __name__ == 'main':
    validatorPkg = Config.getValidatorPkgName()
# Determine the validator for this testcase.
exec 'from '+validatorPkg+' import Validator'

from baseClass import baseClass

# definition of test class
class main(baseClass):
    def runTest(self):
        self.msg('Test started')
        self.logon()

    # ^^^ Insert new recordings here. (Do not remove this line.)


# Code to load and run the test
if __name__ == 'main':
    test = main("main")
    test.Run()

~~~~~~~~~~~~~~~~~~~~​~~~~~~~~~~~~~~~~~~~~​~~~~~~~~
File baseClass.py
# Generated by MaxQ [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
from PyHttpTestCase import PyHttpTestCase
from com.bitmechanic.maxq import Config
global validatorPkg
if __name__ == 'main':
    validatorPkg = Config.getValidatorPkgName()
# Determine the validator for this testcase.
exec 'from '+validatorPkg+' import Validator'


# definition of test class
class baseClass(PyHttpTestCase):
    def logon(self):
        self.msg('Logon.')

    # ^^^ Insert new recordings here. (Do not remove this line.)


# Code to load and run the test
if __name__ == 'main':
    test = baseClass("baseClass")
    test.logon()

« Previous message in topic | 3 of 4 | Next message in topic »

Messages

Show all messages in topic

Cannot use module "re", why not? Hans Schwaebli <hans_schwaebli at yahoo dot com> Hans Schwaebli <hans_schwaebli at yahoo dot com> 2007-05-19 15:56:19 PDT
     Re: [maxq-users] Cannot use module "re", why not? oliverbock Oliver Bock 2007-05-19 19:29:05 PDT
         Creating a base class hms_suprise john v hite 2007-05-22 08:23:53 PDT
             Re: [maxq-users] Creating a base class oliverbock Oliver Bock 2007-05-22 13:49:49 PDT
Messages per page: