Take the 2-minute tour ×

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:

def globalSetUp():...

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

i am usint python2.6 with unittest2 package.


share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

Why not just rename/alias the function?

def globalSetUp():

setUpModule = globalSetUp

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

share|improve this answer
add comment

Your Answer


