renaming default python-unittest function names

334 Views Asked by At

python's unittest testrunner looks for setUpModule() defined in a file to perform before running any test specified in the module. is there a way to use a decorator or some other tool inorder to rename the function name?

for example:

@somedecorator
def globalSetUp():...

will enable unittest's loader to recognize this function as the setUpModule function.

i am usint python2.6 with unittest2 package.

thanks.

2

There are 2 best solutions below

0
On

Derive from TestCase, and in your subclass call your own setup function in the setUp method. Then create your classes from this new subclass rather than TestCase, and you'll have the desired functionality.

0
On

Why not just rename/alias the function?

def globalSetUp():
    ...

setUpModule = globalSetUp

It's just a single additional line, just like a decorator would be.