Q:

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. 

A:

I think it's valuable to unittest.   I especially think unittesting the except condition is valuable, because it looks like an infrequently executed code path.   
What happens if service.__name__ errors for some strange reason?  then you have another exception being thrown. 
To unittests this without changing anything you could use unittest.mock https://docs.python.org/3/library/unittest.mock.html to patch the multiprocessing import, to provide a mock implemenation that doesn't spawn a process. 
Another option would be to inject the multiprocessing module as a paramter into your function, so that the production code could use multiprocessing and your test could code provide a mock object

