unit testing - How to create an instance of an inherited class in unittest Python so that I can register the instance of that class in simpleXMLRPCServer -
from __future__ import with_statement sikuli.sikuli import * import os import unittest import import xmlrpclib import simplexmlrpcserver, socketserver, threading class simplethreadedxmlrpcserver(socketserver.threadingmixin, simplexmlrpcserver.simplexmlrpcserver): pass class abc(object): def a(self): ........... def b(self): ........... def c(self): ........... class xyz(unittest.testcase,abc): def setup(self): print "inside setup" pass def teardown(self): print "inside teardown" pass def test_1(self): self.a() self.b() self.c() def d(self): print "inside d" return true suite = unittest.testloader().loadtestsfromtestcase(xyz) class serverthread(threading.thread): def __init__(self): threading.thread.__init__(self) self.server = simplethreadedxmlrpcserver(("x.x.x.1", 8000)) #self.server.register_instance() #how register instance of xyz here. def run(self): self.server.serve_forever() server = serverthread() server.start()
so question how register instance of xyz
here. in commented line above can called xmlrpc client like:
client = xmlrpclib.serverproxy("http://x.x.x.2:8000") handraise = client.d() #or other possible way
i know works register_function(d)
want whole class xyz
exposed using register_instance()
.
theoretically should work:
self.server.register_instance(xyz()) # throwed runtest error me
anyways, passing method name explicitly arg in classname inside register_instance like:
self.server.register_instance(xyz("d"))
worked expected me.
, xmlrpc client, call d() like:
handraise = client.d()
Comments
Post a Comment