[wingide-users] RE: global setUp script for unit testing? (and other unittest features)

Warren, Russell russell.warren at newport.com
Sun Feb 24 13:37:23 MST 2008

> I think nose can do things like this (certainly with a plugin).
> Unfortunately, Wing doesn't support nose's test discovery, etc., so it means 
> running your tests outside the IDE.

Never heard of nose... I'll have to check it out.  The nose free unittest on its own has no problem doing what I want.  It is purely the Wing IDE integration I'm struggling with.

In the mean time, python being python I've managed to kluge together a makeshift solution that helps me part way at least... basically I subclass the TestCase and always use that for the zillion test cases in my project.  In the subclass I detect if Wing is in use (conveniently in sys.argv[0]) and do some onetime setup in that case.

My subclass code is below (can't recall if it's going to get wrap-mangled).  It is not standalone, but the idea is there.  It has me using the IDE unittest integration again but I wouldn't want to have to do this every time, or keep growing this hack!  Allowing setup of before/after scripts in the IDE would be muuuuch better.  And, now that I'm using the IDE again, my hatred for the default exploded treeview is rising dangerously... can't think of a hack fix for that at the moment!


class BaseUnitTest(unittest.TestCase):
    ServerProxy = None  # for all derived classes to use
    BaseSetupComplete = False
    SetupLock = threading.Lock() #in case test cases are ever run on a thread each
    ServerInstance = None
    ServerThread = None
    def setUp(self):
        BaseUnitTest.SetupLock.acquire() # in case unit tests are run in threads
            if not BaseUnitTest.BaseSetupComplete: #don't want to do this every bleeding time!
                print "** INITIALIZING BASE UNIT TEST **"
                cp = ConfigParser.ConfigParser()
                rpcServerURL = cp.get("ServerConfig", "ServerURL")
                BaseUnitTest.ServerProxy = RpcServerProxy(rpcServerURL)
                sp = BaseUnitTest.ServerProxy = RpcServerProxy(rpcServerURL)
                #if running as unittests from Wing, we may need to launch the server...
                if "wing" in sys.argv[0]: #we are running from Wing
                    print "** RUNNING FROM WING IDE **"
                    import socket
                    #from pprint import pprint as pp
                    #if the server is running, do nothing.  If not, start one up.
                        print "** SERVER DETECTED **"
                    except socket.error:
                        print "** NO SERVER DETECTED - STARTING ONE UP **"
                        import RpcServer
                        #launch server, keeping an instance of it to keep it alive and
                        #send it the rpc search path using __file__ to figure out where
                        #the heck it is
                        (BaseUnitTest.ServerInstance, BaseUnitTest.ServerThread) = \
                #endif - Wing unit test detection
                BaseUnitTest.BaseSetupComplete = True

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20080224/d642ad00/attachment.html

More information about the wingide-users mailing list