mardi 23 décembre 2014

Sharing objects between setup and teardown functions in nose

I'm using nose and I need to start an HTTP server for a test. I'm starting it in the setup function, and stopping it in the teardown function like this:



from my_service import MyClient, MyServer


def setup():
global server
server = MyServer()
server.start()

def teardown():
server.stop()


def test_client():
client = MyClient('localhost', server.port)
assert client.get_colour() == "blue"


Is there a more elegant way to have the server object available to teardown function and tests other than this global variable? Perhaps a value returned from setup which would be passed as an argument to tests and teardown?


Aucun commentaire:

Enregistrer un commentaire