Python unittest with expensive setup

Posted by Staale on Stack Overflow See other posts from Stack Overflow or by Staale
Published on 2009-01-08T07:00:36Z Indexed on 2011/01/02 11:54 UTC
Read the original article Hit count: 212

Filed under:
|

My test file is basically:

class Test(unittest.TestCase):
    def testOk():
        pass

if __name__ == "__main__":
    expensiveSetup()
    try:
        unittest.main()
    finally:
        cleanUp()

However, I do wish to run my test through Netbeans testing tools, and to do that I need unittests that don't rely on an environment setup done in main. Looking at http://stackoverflow.com/questions/402483/caching-result-of-setup-using-python-unittest - it recommends using Nose. However, I don't think Netbeans supports this. I didn't find any information indicating that it does. Additionally, I am the only one here actually writing tests, so I don't want to introduce additional dependencies for the other 2 developers unless they are needed.

How can I do the setup and cleanup once for all the tests in my TestSuite?

The expensive setup here is creating some files with dummy data, as well as setting up and tearing down a simple xml-rpc server. I also have 2 test classes, one testing locally and one testing all methods over xml-rpc.

© Stack Overflow or respective owner

Related posts about python

Related posts about unit-testing