lundi 7 décembre 2015

Unit testing a function that triggers a new process

I am looking to write unit tests to existing functionality, and I came across to the below:

I have a function that spins a new process when bringing up a service or list of services, the code looks something like this:

def run_consumer(self, services):
    for service in services: #services is an array of functions which initialize a service
        try:
            name = service.__name__
            process = multiprocessing.Process(target=service, name = service.__name__, args=self.some_arg)
            process.start()
            self.track_services[name].append(process) #defined in the init
        except Exception as ex:
            print('service "{0}" failed with error: {1}'.format(name, ex))

What I am trying to figure out is if there is any value adding a unit test to this function, and if yes, what would it look like... I am using unittest.

Aucun commentaire:

Enregistrer un commentaire