Fix bug in generation of test handles